mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 21:58:16 +08:00
chore(platform): Make "velocity" to "adventure".
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>3.1.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
|
||||
<deps.adventure.version>4.24.0</deps.adventure.version>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-velocity</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Adventure</name>
|
||||
<description>轻松(做)配置,适用于基于Adventure的平台(如Velocity、Paper),可用JSON与YAML格式。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-yaml</artifactId>
|
||||
<version>${deps.configured.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>${deps.adventure.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||
<version>${deps.adventure.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-plain</artifactId>
|
||||
<version>${deps.adventure.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>${deps.adventure.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cc.carm.lib.mineconfiguration.adventure;
|
||||
|
||||
import cc.carm.lib.configuration.Configuration;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLSource;
|
||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MineConfiguration extends AbstractConfiguration<ConfigurationHolder<YAMLSource>> {
|
||||
|
||||
public MineConfiguration(@NotNull File pluginDataFolder) {
|
||||
super(
|
||||
YAMLConfigFactory.from(pluginDataFolder, "config.yml").build(),
|
||||
YAMLConfigFactory.from(pluginDataFolder, "messages.yml").build()
|
||||
);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||
@NotNull Configuration configRoot,
|
||||
@NotNull Configuration messageRoot) {
|
||||
this(pluginDataFolder);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||
@NotNull Class<? extends Configuration> configRoot,
|
||||
@NotNull Class<? extends Configuration> messageRoot) {
|
||||
this(pluginDataFolder);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package cc.carm.lib.mineconfiguration.adventure.value;
|
||||
|
||||
import cc.carm.lib.configuration.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.value.text.ConfiguredText;
|
||||
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessage extends ConfiguredText<Component, Audience> {
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||
|
||||
public static AtomicReference<ComponentSerializer<?, ?, String>> SERIALIZER = new AtomicReference<>(LEGACY_SERIALIZER);
|
||||
|
||||
@NotNull
|
||||
|
||||
public static ConfiguredMessage.Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage ofString(@NotNull String... messages) {
|
||||
return create().defaults(messages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextContents, TextContents> manifest,
|
||||
@NotNull BiFunction<Audience, String, String> parser,
|
||||
@NotNull BiFunction<Audience, String, Component> compiler,
|
||||
@NotNull BiConsumer<Audience, List<Component>> dispatcher,
|
||||
@NotNull String[] params) {
|
||||
super(manifest, parser, compiler, dispatcher, params);
|
||||
}
|
||||
|
||||
public void sendActionBar(Audience audience, Object... values) {
|
||||
Component content = prepare(values).parseLine(audience, (sender, message) -> Component.text(message));
|
||||
if (content != null) audience.sendActionBar(content);
|
||||
}
|
||||
|
||||
public static class Builder extends ConfiguredText.Builder<Component, Audience, Builder> {
|
||||
|
||||
public Builder() {
|
||||
super();
|
||||
this.parser = (receiver, message) -> ColorParser.parse(message);
|
||||
this.compiler = (receiver, message) -> SERIALIZER.get().deserialize(message);
|
||||
this.dispatcher = (receiver, message) -> message.forEach(receiver::sendMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage build() {
|
||||
return new ConfiguredMessage(buildManifest(), this.parser, this.compiler, this.dispatcher, this.params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage.Builder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user