-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(platform): Try to support Velocity
- Loading branch information
Showing
16 changed files
with
698 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
...bukkit/src/main/java/cc/carm/lib/mineconfiguration/bukkit/builder/CraftConfigBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?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>2.9.3</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<properties> | ||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source> | ||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> | ||
</properties> | ||
<artifactId>mineconfiguration-velocity</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>MineConfiguration-Velocity</name> | ||
<description>轻松(做)配置,适用于Velocity的版本,可用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>yamlcommentwriter</artifactId> | ||
<version>${deps.yamlcommentwriter.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>velocitycord-api</artifactId> | ||
<version>1.18-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>velocitycord-api</artifactId> | ||
<version>1.18-R0.1-SNAPSHOT</version> | ||
<type>javadoc</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
31 changes: 31 additions & 0 deletions
31
...form/velocity/src/main/java/cc/carm/lib/mineconfiguration/velocity/BungeeConfigValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cc.carm.lib.mineconfiguration.velocity; | ||
|
||
import cc.carm.lib.configuration.core.source.ConfigurationProvider; | ||
import cc.carm.lib.configuration.core.value.ValueManifest; | ||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue; | ||
import cc.carm.lib.mineconfiguration.velocity.builder.VelocityConfigBuilder; | ||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider; | ||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeSectionWrapper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> { | ||
|
||
public static @NotNull VelocityConfigBuilder builder() { | ||
return new VelocityConfigBuilder(); | ||
} | ||
|
||
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) { | ||
super(manifest); | ||
} | ||
|
||
public BungeeConfigProvider getBukkitProvider() { | ||
ConfigurationProvider<?> provider = getProvider(); | ||
if (provider instanceof BungeeConfigProvider) return (BungeeConfigProvider) getProvider(); | ||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider"); | ||
} | ||
|
||
public BungeeSectionWrapper getBukkitConfig() { | ||
return getBukkitProvider().getConfiguration(); | ||
} | ||
|
||
} |
123 changes: 123 additions & 0 deletions
123
...form/velocity/src/main/java/cc/carm/lib/mineconfiguration/velocity/MineConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package cc.carm.lib.mineconfiguration.velocity; | ||
|
||
import cc.carm.lib.configuration.core.Configuration; | ||
import cc.carm.lib.configuration.core.ConfigurationRoot; | ||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider; | ||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.config.ConfigurationProvider; | ||
import net.md_5.bungee.config.JsonConfiguration; | ||
import net.md_5.bungee.config.YamlConfiguration; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> { | ||
|
||
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) { | ||
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader); | ||
try { | ||
provider.initializeFile(source); | ||
provider.initializeConfig(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return provider; | ||
} | ||
|
||
public static BungeeConfigProvider from(File file, String source) { | ||
return fromYAML(file, source); | ||
} | ||
|
||
public static BungeeConfigProvider from(File file) { | ||
return from(file, file.getName()); | ||
} | ||
|
||
public static BungeeConfigProvider from(String fileName) { | ||
return from(fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider from(String fileName, String source) { | ||
return from(new File(fileName), source); | ||
} | ||
|
||
public static BungeeConfigProvider from(Plugin plugin, String fileName) { | ||
return from(plugin, fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider from(Plugin plugin, String fileName, String source) { | ||
return from(new File(plugin.getDataFolder(), fileName), source); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(File file, String source) { | ||
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class)); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(String fileName, String source) { | ||
return fromYAML(new File(fileName), source); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(File file) { | ||
return fromYAML(file, file.getName()); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(String fileName) { | ||
return fromYAML(fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName) { | ||
return fromYAML(plugin, fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName, String source) { | ||
return fromYAML(new File(plugin.getDataFolder(), fileName), source); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(File file, String source) { | ||
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class)); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(String fileName, String source) { | ||
return fromJSON(new File(fileName), source); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(File file) { | ||
return fromJSON(file, file.getName()); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(String fileName) { | ||
return fromJSON(fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName) { | ||
return fromJSON(plugin, fileName, fileName); | ||
} | ||
|
||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName, String source) { | ||
return fromJSON(new File(plugin.getDataFolder(), fileName), source); | ||
} | ||
|
||
|
||
public MineConfiguration(@NotNull Plugin plugin) { | ||
super(from(plugin, "config.yml"), from(plugin, "messages.yml")); | ||
} | ||
|
||
public MineConfiguration(@NotNull Plugin plugin, | ||
@NotNull Configuration configRoot, | ||
@NotNull Configuration messageRoot) { | ||
this(plugin); | ||
initializeConfig(configRoot); | ||
initializeMessage(messageRoot); | ||
} | ||
|
||
public MineConfiguration(@NotNull Plugin plugin, | ||
@NotNull Class<? extends Configuration> configRoot, | ||
@NotNull Class<? extends Configuration> messageRoot) { | ||
this(plugin); | ||
initializeConfig(configRoot); | ||
initializeMessage(messageRoot); | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...src/main/java/cc/carm/lib/mineconfiguration/velocity/builder/AbstractVelocityBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cc.carm.lib.mineconfiguration.velocity.builder; | ||
|
||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider; | ||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder; | ||
|
||
public abstract class AbstractVelocityBuilder<T, B extends AbstractVelocityBuilder<T, B>> | ||
extends AbstractConfigBuilder<T, B, BungeeConfigProvider> { | ||
|
||
public AbstractVelocityBuilder() { | ||
super(BungeeConfigProvider.class); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...y/src/main/java/cc/carm/lib/mineconfiguration/velocity/builder/VelocityConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cc.carm.lib.mineconfiguration.velocity.builder; | ||
|
||
import cc.carm.lib.mineconfiguration.velocity.builder.message.BungeeMessageBuilder; | ||
import cc.carm.lib.configuration.core.builder.ConfigBuilder; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class VelocityConfigBuilder extends ConfigBuilder { | ||
|
||
public @NotNull BungeeMessageBuilder createMessage() { | ||
return new BungeeMessageBuilder(); | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ain/java/cc/carm/lib/mineconfiguration/velocity/builder/message/BungeeMessageBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cc.carm.lib.mineconfiguration.velocity.builder.message; | ||
|
||
import cc.carm.lib.easyplugin.utils.ColorParser; | ||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig; | ||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder; | ||
import net.md_5.bungee.api.CommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> { | ||
|
||
|
||
public BungeeMessageBuilder() { | ||
super(CommandSender.class, TextConfig.class); | ||
} | ||
|
||
@Override | ||
public @NotNull <M> BungeeMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) { | ||
return new BungeeMessageValueBuilder<>(parser); | ||
} | ||
|
||
@Override | ||
public @NotNull <M> BungeeMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) { | ||
return new BungeeMessageListBuilder<>(parser); | ||
} | ||
|
||
public @NotNull BungeeMessageValueBuilder<String> asStringValue() { | ||
return asValue(defaultParser()).whenSend(CommandSender::sendMessage); | ||
} | ||
|
||
public @NotNull BungeeMessageListBuilder<String> asStringList() { | ||
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage)); | ||
} | ||
|
||
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() { | ||
return (receiver, message) -> ColorParser.parse(message); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...java/cc/carm/lib/mineconfiguration/velocity/builder/message/BungeeMessageListBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cc.carm.lib.mineconfiguration.velocity.builder.message; | ||
|
||
import cc.carm.lib.configuration.core.value.ValueManifest; | ||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig; | ||
import cc.carm.lib.mineconfiguration.velocity.value.ConfiguredMessageList; | ||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder; | ||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils; | ||
import net.md_5.bungee.api.CommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.function.BiFunction; | ||
|
||
public class BungeeMessageListBuilder<M> | ||
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> { | ||
|
||
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) { | ||
super(CommandSender.class, TextConfig::of, parser); | ||
} | ||
|
||
@Override | ||
protected @NotNull BungeeMessageListBuilder<M> getThis() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull ConfiguredMessageList<M> build() { | ||
return new ConfiguredMessageList<>( | ||
buildManifest(TextConfig.of(new ArrayList<>())), | ||
ParamsUtils.formatParams(this.paramFormatter, this.params), | ||
this.messageParser, this.sendFunction | ||
); | ||
} | ||
} |
Oops, something went wrong.