mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Configs and per-user localisations (#149)
Co-authored-by: jmp <[email protected]> Co-authored-by: broccolai <[email protected]>
This commit is contained in:
35 files changed
+557
-223
No files matched your search
@@ -9,10 +9,12 @@ import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public abstract class CarbonChatCommon implements CarbonChat {
|
||||
|
||||
private final CarbonMessageService messageService;
|
||||
@@ -31,12 +33,14 @@ public abstract class CarbonChatCommon implements CarbonChat {
|
||||
|
||||
this.messageService.exampleCommandFeedback(sender, this.messageService.pluginName());
|
||||
|
||||
if (sender instanceof PlayerCommander) {
|
||||
final Component itemComponent = ((PlayerCommander) sender).carbonPlayer().createItemHoverComponent();
|
||||
if (sender instanceof PlayerCommander player) {
|
||||
this.messageService.localeTestMessage(player.carbonPlayer());
|
||||
|
||||
final Component itemComponent = player.carbonPlayer().createItemHoverComponent();
|
||||
if (itemComponent != empty()) {
|
||||
sender.sendMessage(TextComponent.ofChildren(text("Item: "), itemComponent));
|
||||
player.sendMessage(TextComponent.ofChildren(text("Item: "), itemComponent));
|
||||
} else {
|
||||
sender.sendMessage(text("You are not holding an item!"));
|
||||
player.sendMessage(text("You are not holding an item!"));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -4,30 +4,60 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.proximyst.moonshine.Moonshine;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.common.channels.BasicChatChannel;
|
||||
import net.draycia.carbon.common.config.ConfigLoader;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageParser;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageSender;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageSource;
|
||||
import net.draycia.carbon.common.messages.ComponentPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.ServerReceiverResolver;
|
||||
import net.draycia.carbon.common.messages.UUIDPlaceholderResolver;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonCommonModule extends AbstractModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public BasicChatChannel basicChat(final CarbonMessageService service) {
|
||||
return new BasicChatChannel(service);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public PrimaryConfig primaryConfig(final ConfigLoader configLoader) throws IOException {
|
||||
final @Nullable PrimaryConfig primaryConfig =
|
||||
configLoader.load(PrimaryConfig.class, "config.conf");
|
||||
|
||||
if (primaryConfig == null) {
|
||||
throw new IllegalStateException("Primary configuration was unable to load!");
|
||||
}
|
||||
|
||||
return primaryConfig;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public CarbonMessageService messageService(
|
||||
final @NonNull ServerReceiverResolver serverReceiverResolver,
|
||||
final @NonNull ComponentPlaceholderResolver<Audience> componentPlaceholderResolver,
|
||||
final @NonNull CarbonMessageSource carbonMessageSource,
|
||||
final @NonNull CarbonMessageParser carbonMessageParser,
|
||||
final @NonNull CarbonMessageSender carbonMessageSender
|
||||
final ServerReceiverResolver serverReceiverResolver,
|
||||
final ComponentPlaceholderResolver<Audience> componentPlaceholderResolver,
|
||||
final UUIDPlaceholderResolver<Audience> uuidPlaceholderResolver,
|
||||
final CarbonMessageSource carbonMessageSource,
|
||||
final CarbonMessageParser carbonMessageParser,
|
||||
final CarbonMessageSender carbonMessageSender
|
||||
) {
|
||||
return Moonshine.<Audience>builder()
|
||||
.receiver(serverReceiverResolver)
|
||||
.placeholder(Component.class, componentPlaceholderResolver)
|
||||
.placeholder(UUID.class, uuidPlaceholderResolver)
|
||||
.source(carbonMessageSource)
|
||||
.parser(carbonMessageParser)
|
||||
.sender(carbonMessageSender)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.draycia.carbon.common;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface CarbonJar {
|
||||
}
|
||||
@@ -8,6 +8,6 @@ import java.lang.annotation.Target;
|
||||
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target({ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface ForCarbon {
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class BasicChatChannel implements ChatChannel {
|
||||
|
||||
private final Key key = Key.key("carbon", "vanilla");
|
||||
|
||||
private final CarbonMessageService service;
|
||||
|
||||
public BasicChatChannel(final CarbonMessageService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component render(
|
||||
final CarbonPlayer sender,
|
||||
final Audience recipient,
|
||||
final Component message,
|
||||
final Component originalMessage
|
||||
) {
|
||||
// TODO: Once per-user is setup, use the service for the recipient?
|
||||
// TODO: Or, have the MessageSource do the per-use for us.
|
||||
return this.service.basicChatFormat(
|
||||
recipient,
|
||||
sender.uuid(),
|
||||
sender.displayName(),
|
||||
sender.username(),
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Key key() {
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class VanillaChatChannel implements ChatChannel {
|
||||
|
||||
private final @NonNull ChatComponentRenderer renderer =
|
||||
(sender, recipient, message, originalMessage) -> {
|
||||
final var clickEvent = ClickEvent.suggestCommand("/msg " + sender.username());
|
||||
final var hoverEvent = HoverEvent.showEntity(Key.key("player"),
|
||||
sender.uuid(), text(sender.username()));
|
||||
|
||||
final var name = sender.displayName()
|
||||
.clickEvent(clickEvent)
|
||||
.hoverEvent(hoverEvent)
|
||||
.insertion(sender.username());
|
||||
|
||||
return translatable("chat.type.text", name.color(TextColor.color(0xff0000)), message);
|
||||
};
|
||||
|
||||
private final Key key = Key.key("carbon", "vanilla");
|
||||
|
||||
@Override
|
||||
public ChatComponentRenderer renderer() {
|
||||
return this.renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Key key() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +1,60 @@
|
||||
package net.draycia.carbon.common.config;
|
||||
|
||||
import java.io.File;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import net.draycia.carbon.common.ForCarbon;
|
||||
import net.kyori.adventure.serializer.configurate4.ConfigurateComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ConfigLoader {
|
||||
|
||||
public CommentedConfigurationNode loadConfig(final File file) throws ConfigurateException {
|
||||
final var builder = HoconConfigurationLoader.builder().prettyPrinting(true);
|
||||
private final Path dataDirectory;
|
||||
|
||||
final var loader = this.loadConfigFile(builder, file);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
if (!file.exists()) {
|
||||
loader.save(node);
|
||||
}
|
||||
|
||||
return node;
|
||||
@Inject
|
||||
public ConfigLoader(@ForCarbon final @NonNull Path dataDirectory) {
|
||||
this.dataDirectory = dataDirectory;
|
||||
}
|
||||
|
||||
private HoconConfigurationLoader loadConfigFile(final HoconConfigurationLoader.Builder builder, final File config) {
|
||||
return builder
|
||||
public <T> @Nullable T load(final Class<T> clazz, final String fileName) throws IOException {
|
||||
if (!Files.exists(this.dataDirectory)) {
|
||||
Files.createDirectories(this.dataDirectory);
|
||||
}
|
||||
|
||||
final Path file = this.dataDirectory.resolve(fileName);
|
||||
|
||||
final var loader = HoconConfigurationLoader.builder()
|
||||
.prettyPrinting(true)
|
||||
.defaultOptions(opts -> {
|
||||
final ConfigurateComponentSerializer serializer = ConfigurateComponentSerializer.configurate();
|
||||
final ConfigurateComponentSerializer serializer =
|
||||
ConfigurateComponentSerializer.configurate();
|
||||
|
||||
return opts.shouldCopyDefaults(true).serializers(serializerBuilder ->
|
||||
serializerBuilder.registerAll(serializer.serializers()));
|
||||
})
|
||||
.file(config)
|
||||
.path(file)
|
||||
.build();
|
||||
|
||||
try {
|
||||
final var node = loader.load();
|
||||
final T config = node.get(clazz);
|
||||
|
||||
if (!Files.exists(file)) {
|
||||
node.set(clazz, config);
|
||||
loader.save(node);
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (final ConfigurateException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.draycia.carbon.common.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ConfigSerializable
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class PrimaryConfig {
|
||||
|
||||
@Comment("The default locale for plugin messages.")
|
||||
private String defaultLocale = "en_US";
|
||||
|
||||
public String defaultLocale() {
|
||||
return this.defaultLocale;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.draycia.carbon.common.messages;
|
||||
import com.proximyst.moonshine.annotation.Message;
|
||||
import com.proximyst.moonshine.annotation.Placeholder;
|
||||
import com.proximyst.moonshine.annotation.Receiver;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@@ -20,6 +21,18 @@ public interface CarbonMessageService {
|
||||
@Placeholder final String message
|
||||
);
|
||||
|
||||
@Message("test.phrase")
|
||||
void localeTestMessage(@Receiver final Audience audience);
|
||||
|
||||
@Message("channel.format.basic")
|
||||
Component basicChatFormat(
|
||||
@Receiver final Audience audience,
|
||||
@Placeholder UUID uuid,
|
||||
@Placeholder Component displayname,
|
||||
@Placeholder String username,
|
||||
@Placeholder Component message
|
||||
);
|
||||
|
||||
@Message("placeholders.plugin")
|
||||
Component pluginName();
|
||||
|
||||
|
||||
@@ -3,71 +3,126 @@ package net.draycia.carbon.common.messages;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.proximyst.moonshine.message.IMessageSource;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.CarbonJar;
|
||||
import net.draycia.carbon.common.ForCarbon;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class CarbonMessageSource implements IMessageSource<String, Audience> {
|
||||
public final class CarbonMessageSource implements IMessageSource<String, Audience> {
|
||||
|
||||
private final Properties properties;
|
||||
private final Locale defaultLocale;
|
||||
private final Map<Locale, Properties> locales = new HashMap<>();
|
||||
private final Path pluginJar;
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
CarbonMessageSource(final @ForCarbon Path dataDirectory) throws IOException {
|
||||
final var directoryFile = dataDirectory.toFile();
|
||||
private CarbonMessageSource(
|
||||
final @ForCarbon Path dataDirectory,
|
||||
final PrimaryConfig primaryConfig,
|
||||
final @CarbonJar Path pluginJar,
|
||||
final Logger logger
|
||||
) throws IOException {
|
||||
this.pluginJar = pluginJar;
|
||||
this.logger = logger;
|
||||
|
||||
if (!directoryFile.exists()) {
|
||||
directoryFile.mkdirs();
|
||||
final @Nullable Locale configLocale = Translator.parseLocale(primaryConfig.defaultLocale());
|
||||
|
||||
if (configLocale != null) {
|
||||
this.defaultLocale = configLocale;
|
||||
} else {
|
||||
this.defaultLocale = Locale.ENGLISH;
|
||||
}
|
||||
|
||||
this.properties = new Properties();
|
||||
final Path localeDirectory = dataDirectory.resolve("locale");
|
||||
|
||||
// TODO: read file name from config, allow users to specify which file.
|
||||
// TODO: have a fallback that uses messages.properties in the jar
|
||||
// so that any missing entries in the user's file will be resolvable.
|
||||
final var fileName = "messages.properties";
|
||||
final var file = dataDirectory.resolve(fileName).toFile();
|
||||
|
||||
if (file.isFile()) {
|
||||
try (final Reader reader = new FileReader(file, StandardCharsets.UTF_8)) {
|
||||
this.properties.load(reader);
|
||||
}
|
||||
// Create locale directory
|
||||
if (!Files.exists(localeDirectory)) {
|
||||
Files.createDirectories(localeDirectory);
|
||||
}
|
||||
|
||||
boolean write = !file.isFile();
|
||||
this.walkPluginJar(stream -> stream.filter(Files::isRegularFile)
|
||||
.filter(it -> {
|
||||
final String pathString = it.toString();
|
||||
return pathString.startsWith("/locale/messages-")
|
||||
&& pathString.endsWith(".properties");
|
||||
})
|
||||
.forEach(localeFile -> {
|
||||
final String localeString = localeFile.getFileName().toString().substring("messages-".length()).replace(".properties", "");
|
||||
// MC uses no_NO when the player selects nb_NO...
|
||||
final @Nullable Locale locale = Translator.parseLocale(localeString.replace("nb_NO", "no_NO"));
|
||||
|
||||
try (final InputStream stream = CarbonChat.class.getResourceAsStream("/" + fileName)) {
|
||||
final Properties packaged = new Properties();
|
||||
packaged.load(stream);
|
||||
if (locale == null) {
|
||||
this.logger.warn("Unknown locale '{}'?", localeString);
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Map.Entry<Object, Object> entry : packaged.entrySet()) {
|
||||
write |= this.properties.putIfAbsent(entry.getKey(), entry.getValue()) == null;
|
||||
}
|
||||
}
|
||||
this.logger.info("Found locale {} ({}) in: {}", locale.getDisplayName(), locale, localeFile); // todo - debug
|
||||
|
||||
if (write) {
|
||||
try (final Writer writer = new FileWriter(file, StandardCharsets.UTF_8)) {
|
||||
this.properties.store(writer, null);
|
||||
}
|
||||
}
|
||||
final Properties properties = new Properties();
|
||||
|
||||
try {
|
||||
this.loadProperties(properties, localeDirectory, localeFile);
|
||||
this.locales.put(locale, properties);
|
||||
|
||||
this.logger.info("Successfully loaded locale {} ({})", locale.getDisplayName(), locale);
|
||||
} catch (final IOException ex) {
|
||||
this.logger.warn("Unable to load locale {} ({}) from source: {}", locale.getDisplayName(), locale, localeFile, ex);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String message(final String key, final Audience receiver) {
|
||||
final String value = this.properties.getProperty(key);
|
||||
if (receiver instanceof CarbonPlayer player) {
|
||||
return this.forPlayer(key, player);
|
||||
} else {
|
||||
return this.forAudience(key, receiver);
|
||||
}
|
||||
}
|
||||
|
||||
private String forPlayer(final String key, final CarbonPlayer player) {
|
||||
if (player.locale() != null) {
|
||||
final var properties = this.locales.get(player.locale());
|
||||
|
||||
if (properties != null) {
|
||||
final var message = properties.getProperty(key);
|
||||
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.forAudience(key, player);
|
||||
}
|
||||
|
||||
private String forAudience(final String key, final Audience audience) {
|
||||
final String value = this.locales.get(this.defaultLocale).getProperty(key);
|
||||
|
||||
if (value == null) {
|
||||
throw new IllegalStateException("No message mapping for key " + key);
|
||||
}
|
||||
@@ -75,4 +130,56 @@ public class CarbonMessageSource implements IMessageSource<String, Audience> {
|
||||
return value;
|
||||
}
|
||||
|
||||
private void walkPluginJar(final Consumer<Stream<Path>> user) throws IOException {
|
||||
if (Files.isDirectory(this.pluginJar)) {
|
||||
try (final var stream = Files.walk(this.pluginJar)) {
|
||||
user.accept(stream);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try (final FileSystem jar = FileSystems.newFileSystem(this.pluginJar, this.getClass().getClassLoader())) {
|
||||
final Path root = jar.getRootDirectories()
|
||||
.iterator()
|
||||
.next();
|
||||
try (final var stream = Files.walk(root)) {
|
||||
user.accept(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProperties(
|
||||
final Properties properties,
|
||||
final Path localeDirectory,
|
||||
final Path localeFile
|
||||
) throws IOException {
|
||||
final Path savedFile = localeDirectory.resolve(localeFile.getFileName().toString());
|
||||
|
||||
// If the file in the localeDirectory exists, read it to the properties
|
||||
if (Files.isRegularFile(savedFile)) {
|
||||
final InputStream inputStream = Files.newInputStream(savedFile);
|
||||
try (final Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
|
||||
properties.load(reader);
|
||||
}
|
||||
}
|
||||
|
||||
boolean write = !Files.isRegularFile(savedFile);
|
||||
|
||||
// Read the file in the jar and add missing entries
|
||||
try (final InputStream stream = Files.newInputStream(localeFile)) {
|
||||
final Properties packaged = new Properties();
|
||||
packaged.load(stream);
|
||||
|
||||
for (final Map.Entry<Object, Object> entry : packaged.entrySet()) {
|
||||
write |= properties.putIfAbsent(entry.getKey(), entry.getValue()) == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Write properties back to file
|
||||
if (write) {
|
||||
try (final Writer outputStream = Files.newBufferedWriter(savedFile)) {
|
||||
properties.store(outputStream, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public final class ServerReceiverResolver implements IReceiverResolver<Audience>
|
||||
private final @NonNull CarbonServer carbonServer;
|
||||
|
||||
@Inject
|
||||
public ServerReceiverResolver(final @NonNull CarbonServer carbonServer) {
|
||||
public ServerReceiverResolver(final CarbonServer carbonServer) {
|
||||
this.carbonServer = carbonServer;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.draycia.carbon.common.messages;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.proximyst.moonshine.component.placeholder.IPlaceholderResolver;
|
||||
import com.proximyst.moonshine.component.placeholder.PlaceholderContext;
|
||||
import com.proximyst.moonshine.component.placeholder.ResolveResult;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class UUIDPlaceholderResolver<R> implements IPlaceholderResolver<R, UUID> {
|
||||
|
||||
public ResolveResult resolve(
|
||||
final String placeholderName,
|
||||
final UUID value,
|
||||
final PlaceholderContext<R> ctx,
|
||||
final Multimap<String, @Nullable Object> flags
|
||||
) {
|
||||
return ResolveResult.ok(placeholderName, value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package net.draycia.carbon.common.users;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.channels.VanillaChatChannel;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -21,7 +20,7 @@ public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudi
|
||||
protected Component displayName;
|
||||
protected final UUID uuid;
|
||||
protected final Identity identity;
|
||||
protected ChatChannel selectedChannel;
|
||||
protected @Nullable ChatChannel selectedChannel;
|
||||
|
||||
protected CarbonPlayerCommon(
|
||||
final String username,
|
||||
@@ -33,7 +32,7 @@ public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudi
|
||||
this.displayName = displayName;
|
||||
this.uuid = uuid;
|
||||
this.identity = identity;
|
||||
this.selectedChannel = new VanillaChatChannel(); // TODO: replace, persist and use global instance
|
||||
this.selectedChannel = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +61,7 @@ public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudi
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel selectedChannel() {
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
return this.selectedChannel;
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -1,3 +1,6 @@
|
||||
example.command.hello=<green>Hello from </green><plugin><green>!</green>
|
||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message: '<message>'
|
||||
placeholders.plugin=<#1DA3A6><bold>Carbon</bold></#1DA3A6>
|
||||
test.phrase=English: Has anyone really been far even as decided to use even go want to do look more like?
|
||||
channel.format.basic=<displayname>\: <message>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
example.command.hello=<green>Hello from </green><plugin><green>\!</green>
|
||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message\: '<message>'
|
||||
placeholders.plugin=<\#1DA3A6><bold>Carbon</bold></\#1DA3A6>
|
||||
test.phrase=bokmål: I noen tilfeller skulle man gjerne sett for seg at kongen bryr seg om sitt folk. Etter festen i '97, har dette blitt klart at er helt rett: han brakte med seg flere soldater og sammen giljotinerte de alle deltakere under atten år.
|
||||
channel.format.basic=<displayname>\: <message>
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
example.command.hello=<green>Hello from </green><plugin><green>\!</green>
|
||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message\: '<message>'
|
||||
placeholders.plugin=<\#1DA3A6><bold>Carbon</bold></\#1DA3A6>
|
||||
test.phrase=Nynorsk: Alle menneske er fødde til fridom og med same menneskeverd og menneskerettar. Dei har fått fornuft og samvit og skal leve med kvarandre som brør.
|
||||
channel.format.basic=<displayname>\: <message>
|
||||
@@ -1,3 +0,0 @@
|
||||
example.command.hello=<green>Hello from </green><plugin><green>\!</green>
|
||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message\: '<message>'
|
||||
placeholders.plugin=<\#1DA3A6><bold>Carbon</bold></\#1DA3A6>
|
||||
Reference in new issue
Block a user