1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-05 06:51:49 +08:00

Compare commits

...

18 Commits

Author SHA1 Message Date
carm 24ef0b6dcd feat(send): 提供物品预备方法,方便插入lore、修改附魔、flags等 2023-09-07 03:49:15 +08:00
carm a1d6cf1258 feat(send): 提供新消息发送方法,分离玩家参数和消息参数 2023-09-07 02:31:57 +08:00
carm 0f7fc39f87 feat(send): 提供新消息发送方法,分离玩家参数和消息参数 2023-09-06 06:40:52 +08:00
dependabot[bot] 92ecb55a95 chore(deps): bump cc.carm.lib:easyplugin-color from 1.5.6 to 1.5.7 (#40)
Bumps [cc.carm.lib:easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.6 to 1.5.7.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.6...1.5.7)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 01:10:37 +08:00
carm bfd1624e85 chore(update): 适配上游版本更新。 2023-08-29 12:43:49 +08:00
dependabot[bot] 01d3c245a9 chore(deps): bump net.md-5:bungeecord-chat from 1.16-R0.4 to 1.20-R0.1 (#37)
Bumps [net.md-5:bungeecord-chat](https://github.com/SpigotMC/BungeeCord) from 1.16-R0.4 to 1.20-R0.1.
- [Commits](https://github.com/SpigotMC/BungeeCord/commits)

---
updated-dependencies:
- dependency-name: net.md-5:bungeecord-chat
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-08 14:09:36 +08:00
dependabot[bot] 8721c6085f chore(deps): bump com.github.cryptomorin:XSeries from 9.4.0 to 9.5.0 (#36)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.4.0 to 9.5.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.4.0...v9.5.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-08 14:09:23 +08:00
dependabot[bot] eca4d47b8f chore(deps): bump easyconfiguration-core from 3.7.0 to 3.7.1 (#35)
Bumps [easyconfiguration-core](https://github.com/CarmJos/EasyConfiguration) from 3.7.0 to 3.7.1.
- [Release notes](https://github.com/CarmJos/EasyConfiguration/releases)
- [Commits](https://github.com/CarmJos/EasyConfiguration/compare/3.7.0...3.7.1)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyconfiguration-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-20 08:49:44 +08:00
dependabot[bot] 3750ac7d58 chore(deps): bump easyconfiguration-core from 3.6.0 to 3.7.0 (#34)
Bumps [easyconfiguration-core](https://github.com/CarmJos/EasyConfiguration) from 3.6.0 to 3.7.0.
- [Release notes](https://github.com/CarmJos/EasyConfiguration/releases)
- [Commits](https://github.com/CarmJos/EasyConfiguration/compare/3.6.0...3.7.0)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyconfiguration-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-11 17:02:40 +08:00
dependabot[bot] d3bdc4ad60 chore(deps): bump easyplugin-color from 1.5.4 to 1.5.6 (#33)
Bumps [easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.4 to 1.5.6.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.4...1.5.6)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 04:03:39 +08:00
dependabot[bot] 6bb6fb1b95 chore(deps): bump maven-shade-plugin from 3.4.1 to 3.5.0 (#32)
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.1 to 3.5.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.1...maven-shade-plugin-3.5.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-17 21:22:09 +08:00
dependabot[bot] dd2499512c chore(deps): bump XSeries from 9.3.1 to 9.4.0 (#31)
Bumps [XSeries](https://github.com/CryptoMorin/XSeries) from 9.3.1 to 9.4.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.3.1...v9.4.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-14 09:58:56 +08:00
dependabot[bot] 3aa0542f01 chore(deps): bump maven-surefire-plugin from 3.1.0 to 3.1.2 (#30)
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.0 to 3.1.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.0...surefire-3.1.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-09 13:36:34 +08:00
dependabot[bot] 4d9d5f5d84 chore(deps): bump maven-release-plugin from 3.0.0 to 3.0.1 (#29)
Bumps [maven-release-plugin](https://github.com/apache/maven-release) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/apache/maven-release/releases)
- [Commits](https://github.com/apache/maven-release/compare/maven-release-3.0.0...maven-release-3.0.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-release-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-06 12:12:30 +08:00
carm 2b31ee1318 fix(item): 修复物品获取后修改被直接应用到缓存导致重复获取第一次物品的问题。 2023-06-01 02:32:45 +08:00
carm 9d6212e5ea feat(conf): 为入口类添加了实例方法,方便快捷创建基础配置和消息配置文件。 2023-05-27 00:22:30 +08:00
carm 8f3d574446 feat(conf): 搭配XSeries实现部分配置类的跨版本支持。 2023-05-27 00:12:37 +08:00
dependabot[bot] 437e1d6d61 chore(deps): bump maven-source-plugin from 3.2.1 to 3.3.0 (#28)
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.1 to 3.3.0.
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.1...maven-source-plugin-3.3.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-23 21:33:19 +08:00
23 changed files with 564 additions and 179 deletions
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.6.0</version>
<version>2.8.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@@ -39,7 +39,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.16-R0.4</version>
<version>1.20-R0.1</version>
<scope>provided</scope>
</dependency>
@@ -0,0 +1,51 @@
package cc.carm.lib.mineconfiguration.common;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import org.jetbrains.annotations.NotNull;
public abstract class AbstractConfiguration<P extends ConfigurationProvider<?>> {
private final P configProvider;
private final P messageProvider;
protected AbstractConfiguration(@NotNull P configProvider, @NotNull P messageProvider) {
this.configProvider = configProvider;
this.messageProvider = messageProvider;
}
public void initializeConfig(@NotNull ConfigurationRoot configRoot) {
this.configProvider.initialize(configRoot);
}
public void initializeMessage(@NotNull ConfigurationRoot messageRoot) {
this.messageProvider.initialize(messageRoot);
}
public void initializeConfig(@NotNull Class<? extends ConfigurationRoot> configRoot) {
this.configProvider.initialize(configRoot);
}
public void initializeMessage(@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this.messageProvider.initialize(messageRoot);
}
public P getConfigProvider() {
return configProvider;
}
public P getMessageProvider() {
return messageProvider;
}
public void reload() throws Exception {
getConfigProvider().reload();
getMessageProvider().reload();
}
public void save() throws Exception {
getConfigProvider().save();
getMessageProvider().save();
}
}
@@ -38,6 +38,16 @@ public interface BaseMessage<R, M> {
@ApiStatus.OverrideOnly
void apply(@NotNull R receiver, @NotNull M message);
/**
* 填入变量值,返回一个准备好待发送的消息。
*
* @param values 变量值
* @return 准备好待发送的消息
*/
default @NotNull PreparedMessage<R, M> prepare(@NotNull Object... values) {
return new PreparedMessage<>(this, values);
}
/**
* 为某位接收者解析此消息。
*
@@ -7,6 +7,7 @@ import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
@@ -47,11 +48,20 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
sendFunction.accept(receiver, message);
}
@Override
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
protected <N> @Nullable N parseTo(@Nullable R sender, @NotNull Map<String, Object> placeholders,
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable N> parser) {
T value = get();
if (value == null || value.getMessage().isEmpty()) return null;
else return value.parse(this.messageParser, sender, placeholders);
else return value.parse(parser, sender, placeholders);
}
public @Nullable String parseString(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
return parseTo(sender, placeholders, (r, s) -> s);
}
@Override
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
return parseTo(sender, placeholders, this.messageParser);
}
public void set(@Nullable String value) {
@@ -62,4 +72,28 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
return textBuilder.apply(value);
}
public abstract class PreparedMessage<P, N> {
protected final @NotNull Object[] values;
protected PreparedMessage(@NotNull Object[] values) {
this.values = values;
}
public Object[] getValues() {
return values;
}
public abstract void to(P receiver);
public void to(Collection<P> receivers) {
receivers.forEach(this::to);
}
public N get(P receiver) {
return null;
}
}
}
@@ -4,6 +4,7 @@ import cc.carm.lib.configuration.core.function.ConfigDataFunction;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -68,14 +69,22 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
.collect(Collectors.toList());
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Object... values) {
return parseToLine(receiver, "\n", ParamsUtils.buildParams(this.params, values));
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
return parseToLine(receiver, "\n", placeholders);
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull String delimiter, @NotNull Map<String, Object> placeholders) {
List<T> list = get();
if (list.isEmpty()) return null;
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
if (String.join("", messages).isEmpty()) return null;
String combined = String.join("\n", messages);
String combined = String.join(delimiter, messages);
T text = textBuilder.apply(combined);
return text.parse(this.messageParser, receiver, placeholders);
@@ -0,0 +1,48 @@
package cc.carm.lib.mineconfiguration.common.value;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PreparedMessage<R, M> {
protected final @NotNull BaseMessage<R, M> message;
protected final @NotNull Object[] values;
protected PreparedMessage(@NotNull BaseMessage<R, M> message, @NotNull Object[] values) {
this.message = message;
this.values = values;
}
/**
* 为某位接收者解析此消息。
*
* @param receiver 接收者
* @return 解析变量后的消息内容
*/
public @Nullable M parse(@Nullable R receiver) {
return message.parse(receiver, values);
}
/**
* 向某位接收者发送消息
*
* @param receiver 消息的接收者
*/
public void to(@Nullable R receiver) {
message.send(receiver, values);
}
/**
* 向某位接收者发送消息
*
* @param receivers 消息的接收者们
*/
public void to(@NotNull Iterable<R> receivers) {
receivers.forEach(this::to);
}
public void toAll() {
to(message.getAllReceivers());
}
}
+9 -10
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.6.0</version>
<version>2.8.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -37,11 +37,18 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.5.0</version>
<scope>compile</scope>
</dependency>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -53,14 +60,6 @@
<scope>provided</scope>
</dependency>
<!--ProtocolLib for general packet's function support-->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
@@ -7,9 +7,6 @@ import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
@@ -17,7 +14,7 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
return new CraftConfigBuilder();
}
public CraftConfigValue(@NotNull ValueManifest<T> manifest) {
protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
super(manifest);
}
@@ -1,12 +1,16 @@
package cc.carm.lib.mineconfiguration.bukkit;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
public class MineConfiguration {
public class MineConfiguration extends AbstractConfiguration<BukkitConfigProvider> {
public static BukkitConfigProvider from(File file, String source) {
BukkitConfigProvider provider = new BukkitConfigProvider(file);
@@ -39,4 +43,24 @@ public class MineConfiguration {
return from(new File(plugin.getDataFolder(), fileName), source);
}
public MineConfiguration(@NotNull JavaPlugin plugin) {
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
}
public MineConfiguration(@NotNull JavaPlugin plugin,
@NotNull ConfigurationRoot configRoot,
@NotNull ConfigurationRoot messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
public MineConfiguration(@NotNull JavaPlugin plugin,
@NotNull Class<? extends ConfigurationRoot> configRoot,
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
}
@@ -6,11 +6,8 @@ import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CraftConfigBuilder extends ConfigBuilder {
@@ -34,12 +31,4 @@ public class CraftConfigBuilder extends ConfigBuilder {
return new SerializableBuilder<>(valueClass);
}
public @NotNull ConfiguredItem ofItem() {
return createItem().build();
}
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
return createItem().defaults(defaultItem).build();
}
}
@@ -2,19 +2,21 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.item;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.UnaryOperator;
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemStack, ItemConfigBuilder> {
protected Material type;
protected short data = 0;
@@ -84,7 +86,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
}
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
public ItemConfigBuilder formatParam(@NotNull UnaryOperator<String> paramFormatter) {
this.paramFormatter = paramFormatter;
return getThis();
}
@@ -104,9 +106,20 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
return this;
}
protected @Nullable ItemConfig buildDefault() {
protected @Nullable ItemStack buildDefault() {
if (this.type == null) return null;
else return new ItemConfig(type, data, name, lore, enchants, flags);
ItemStack item = new ItemStack(type, 1, data);
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
Optional.ofNullable(this.name).ifPresent(meta::setDisplayName);
Optional.ofNullable(this.lore).ifPresent(meta::setLore);
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
flags.forEach(meta::addItemFlags);
item.setItemMeta(meta);
return item;
}
@Override
@@ -1,6 +1,5 @@
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
@@ -9,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.BiFunction;
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
@@ -2,43 +2,29 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.title;
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.bukkit.utils.ProtocolLibHelper;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
@SuppressWarnings("deprecation")
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = (player, fadeIn, stay, fadeOut, line1, line2) -> {
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
try {
ProtocolLibHelper.sendTitle(player, fadeIn, stay, fadeOut, line1, line2);
} catch (Exception ignored) {
}
} else {
player.sendTitle(line1, line2);
}
};
protected @NotNull String[] params = new String[0];
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10;
protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60;
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10;
protected @NotNull TitleSendConsumer sendConsumer;
protected @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
public TitleConfigBuilder() {
this.sendConsumer = TitleConfigBuilder.DEFAULT_TITLE_CONSUMER;
this.sendConsumer = ConfiguredTitle.DEFAULT_TITLE_CONSUMER;
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
}
@@ -47,7 +33,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
return defaults(TitleConfig.of(line1, line2));
}
public @NotNull TitleConfigBuilder whenSend(@NotNull TitleSendConsumer consumer) {
public @NotNull TitleConfigBuilder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
this.sendConsumer = consumer;
return this;
}
@@ -76,7 +62,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
return this;
}
public TitleConfigBuilder formatParam(Function<String, String> paramFormatter) {
public TitleConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
this.paramFormatter = paramFormatter;
return this;
}
@@ -26,6 +26,8 @@ public class ItemConfig {
protected @NotNull Map<Enchantment, Integer> enchants;
protected @NotNull Set<ItemFlag> flags;
protected int customModelData = 0;
public ItemConfig(@NotNull Material type, @Nullable String name) {
this(type, name, Collections.emptyList());
}
@@ -131,7 +133,7 @@ public class ItemConfig {
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
return deserialize(CraftSectionWrapper.of(section));
}
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
String typeName = section.getString("type");
if (typeName == null) throw new NullPointerException("Item type name is null");
@@ -1,8 +1,8 @@
package cc.carm.lib.mineconfiguration.bukkit.data;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,20 +25,58 @@ public class TitleConfig {
return new TitleConfig(line1, line2);
}
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2,
int fadeIn, int stay, int fadeOut) {
return of(
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
Optional.ofNullable(line2).map(TextConfig::of).orElse(null),
fadeIn, stay, fadeOut
);
}
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2,
int fadeIn, int stay, int fadeOut) {
return new TitleConfig(line1, line2, fadeIn, stay, fadeOut);
}
protected @Nullable TextConfig line1;
protected @Nullable TextConfig line2;
protected final int fadeIn;
protected final int stay;
protected final int fadeOut;
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
this(line1, line2, -1, -1, -1);
}
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2, int fadeIn, int stay, int fadeOut) {
this.line1 = line1;
this.line2 = line2;
this.fadeIn = fadeIn;
this.stay = stay;
this.fadeOut = fadeOut;
}
public void send(@NotNull Player player,
@Range(from = 0L, to = Long.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Long.MAX_VALUE) int stay,
@Range(from = 0L, to = Long.MAX_VALUE) int fadeOut,
@NotNull Map<String, Object> placeholders,
@Nullable TitleSendConsumer sendConsumer) {
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
send(
player,
this.fadeIn < 0 ? 10 : this.fadeIn,
this.stay < 0 ? 60 : this.stay,
this.fadeOut < 0 ? 10 : this.fadeOut,
placeholders,
sendConsumer
);
}
public void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull Map<String, Object> placeholders,
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
if (this.line1 == null && this.line2 == null) return;
if (sendConsumer == null) return;
sendConsumer.send(
@@ -58,11 +96,23 @@ public class TitleConfig {
Map<String, Object> map = new LinkedHashMap<>();
if (this.line1 != null) map.put("line1", this.line1.getMessage());
if (this.line2 != null) map.put("line2", this.line2.getMessage());
if (this.fadeIn > 0) map.put("fadeIn", this.fadeIn);
if (this.stay > 0) map.put("stay", this.stay);
if (this.fadeOut > 0) map.put("fadeOut", this.fadeOut);
return map;
}
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
return of(section.getString("line1"), section.getString("line2"));
public static @Nullable TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
String line1 = section.getString("line1");
String line2 = section.getString("line2");
if (line1 == null && line2 == null) return null;
return of(
line1, line2,
section.getInt("fadeIn", -1),
section.getInt("stay", -1),
section.getInt("fadeOut", -1)
);
}
}
@@ -1,26 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.function;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
@FunctionalInterface
public interface TitleSendConsumer {
/**
* 向目标玩家发送标题文字
*
* @param player 目标玩家
* @param fadeIn 淡入时间 (ticks)
* @param stay 保留时间 (ticks)
* @param fadeOut 淡出时间 (ticks)
* @param line1 第一行文字
* @param line2 第二行文字
*/
void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull String line1, @NotNull String line2);
}
@@ -1,41 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.utils;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ProtocolLibHelper {
@SuppressWarnings("deprecation")
public static void sendTitle(@NotNull Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
if (line1 != null) {
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
packet.getTitleActions().write(0, EnumWrappers.TitleAction.TITLE);
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line1));
pm.sendServerPacket(player, packet, false);
}
if (line2 != null) {
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
packet.getTitleActions().write(0, EnumWrappers.TitleAction.SUBTITLE);
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line2));
pm.sendServerPacket(player, packet, false);
}
PacketContainer timePacket = pm.createPacket(PacketType.Play.Server.TITLE);
timePacket.getTitleActions().write(0, EnumWrappers.TitleAction.TIMES);
timePacket.getIntegers()
.write(0, Math.toIntExact(fadeIn))
.write(1, Math.toIntExact(stay))
.write(2, Math.toIntExact(fadeOut));
pm.sendServerPacket(player, timePacket, false);
}
}
@@ -1,71 +1,252 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import com.cryptomorin.xseries.XItemStack;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^#(.*)#$");
public static ItemConfigBuilder create() {
return CraftConfigValue.builder().createItem();
}
public static ConfiguredItem of() {
return CraftConfigValue.builder().ofItem();
}
public static ConfiguredItem of(@Nullable ItemConfig defaultItem) {
return CraftConfigValue.builder().ofItem(defaultItem);
return new ItemConfigBuilder();
}
protected final @NotNull String[] params;
public ConfiguredItem(@NotNull ValueManifest<ItemConfig> manifest, @NotNull String[] params) {
public ConfiguredItem(@NotNull ValueManifest<ItemStack> manifest, @NotNull String[] params) {
super(
manifest, ItemConfig.class,
getItemParser(), ItemConfig::serialize
manifest, ItemStack.class,
(data, v) -> XItemStack.deserialize((ConfigurationSection) data.getSource()),
XItemStack::serialize
);
this.params = params;
}
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
return (s, d) -> ItemConfig.deserialize(s);
}
public @NotNull String[] getParams() {
return params;
}
public @Nullable ItemStack getItem(@Nullable Player player) {
return getItem(player, 1);
@Override
public @Nullable ItemStack get() {
return Optional.ofNullable(super.get()).map(ItemStack::clone).orElse(null);
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount) {
return getItem(player, amount, new HashMap<>());
public void modifyItem(Consumer<ItemStack> modifier) {
ItemStack item = get();
if (item == null) return;
modifier.accept(item);
set(item);
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Object... values) {
return getItem(player, amount, ParamsUtils.buildParams(params, values));
public void modifyMeta(Consumer<ItemMeta> modifier) {
modifyItem(item -> {
ItemMeta meta = item.getItemMeta();
modifier.accept(meta);
item.setItemMeta(meta);
});
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull String[] params, @NotNull Object[] values) {
return getItem(player, amount, ParamsUtils.buildParams(params, values));
public void setName(@Nullable String name) {
modifyMeta(meta -> meta.setDisplayName(name));
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
return getOptional().map(item -> item.getItemStack(player, amount, placeholders)).orElse(null);
public void setLore(@Nullable List<String> lore) {
modifyMeta(meta -> meta.setLore(lore));
}
public void setLore(String... lore) {
if (lore.length == 0) setLore((List<String>) null);
else setLore(Arrays.asList(lore));
}
public @NotNull PreparedItem prepare(@NotNull Object... values) {
return new PreparedItem(this, values);
}
public @Nullable ItemStack get(@Nullable Player player) {
return get(player, new HashMap<>());
}
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
return get(player, ParamsUtils.buildParams(params, values));
}
public @Nullable ItemStack get(@Nullable Player player,
@NotNull Object[] values,
@NotNull Map<String, List<String>> inserted) {
return get(player, ParamsUtils.buildParams(params, values), inserted);
}
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
return get(player, ParamsUtils.buildParams(params, values));
}
public @Nullable ItemStack get(@Nullable Player player,
@NotNull Map<String, Object> placeholders) {
return get(player, placeholders, new HashMap<>());
}
public @Nullable ItemStack get(@Nullable Player player,
@NotNull Map<String, Object> placeholders,
@NotNull Map<String, List<String>> inserted) {
return get(item -> {
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
List<String> lore = insertLore(meta.getLore(), inserted);
if (!lore.isEmpty()) {
meta.setLore(TextParser.parseList(player, lore, placeholders));
}
String name = meta.getDisplayName();
if (!name.isEmpty()) {
meta.setDisplayName(TextParser.parseText(player, name, placeholders));
}
item.setItemMeta(meta);
});
}
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
return getOptional().map(item -> {
modifier.accept(item);
return item;
}).orElse(null);
}
protected static List<String> insertLore(List<String> original, Map<String, List<String>> inserted) {
if (original == null) return Collections.emptyList();
List<String> finalLore = new ArrayList<>();
for (String line : original) {
if (line == null) continue;
Matcher matcher = LORE_INSERT_PATTERN.matcher(line);
if (!matcher.matches()) {
finalLore.add(line);
} else {
String path = matcher.group(1);
Optional.ofNullable(inserted.get(path)).ifPresent(finalLore::addAll);
}
}
return finalLore;
}
public static class PreparedItem {
protected final @NotNull ConfiguredItem itemConfig;
protected final @NotNull Map<String, List<String>> insertLore = new HashMap<>();
protected @NotNull Object[] values;
protected @NotNull BiConsumer<ItemStack, Player> itemModifier;
protected @NotNull BiConsumer<ItemMeta, Player> metaModifier;
protected PreparedItem(@NotNull ConfiguredItem itemConfig, @NotNull Object[] values) {
this.itemConfig = itemConfig;
this.values = values;
itemModifier = (item, player) -> {
};
metaModifier = (meta, player) -> {
};
}
public PreparedItem modifyMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
this.metaModifier = this.metaModifier.andThen(modifier);
return this;
}
public PreparedItem modifyItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
this.itemModifier = this.itemModifier.andThen(modifier);
return this;
}
public PreparedItem insertLore(String path, List<String> content) {
insertLore.put(path, content);
return this;
}
public PreparedItem insertLore(String path, String... content) {
return insertLore(path, Arrays.asList(content));
}
public PreparedItem insertLore(String path, ConfiguredList<String> content) {
return insertLore(path, content.copy());
}
public PreparedItem insertLore(String path, ConfiguredMessage<String> content, Object... params) {
return insertLore(path, content.parse(null, params));
}
public PreparedItem insertLore(String path, ConfiguredMessageList<String> content, Object... params) {
return insertLore(path, content.parse(null, params));
}
public PreparedItem values(Object... values) {
this.values = values;
return this;
}
public PreparedItem amount(int amount) {
return modifyItem((item, player) -> item.setAmount(amount));
}
public PreparedItem addEnchantment(Enchantment e) {
return addEnchantment(e, 1);
}
public PreparedItem addEnchantment(Enchantment e, int level) {
return addEnchantment(e, level, true);
}
public PreparedItem addEnchantment(Enchantment e, int level, boolean ignoreLevelRestriction) {
return modifyMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
}
public PreparedItem addItemFlags(ItemFlag... flags) {
return modifyMeta((meta, player) -> meta.addItemFlags(flags));
}
public PreparedItem glow() {
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
}
public @Nullable ItemStack get(Player player) {
return Optional.ofNullable(itemConfig.get(player, values, insertLore)).map(item -> {
itemModifier.accept(item, player);
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
metaModifier.accept(meta, player);
item.setItemMeta(meta);
return item;
}).orElse(null);
}
}
}
@@ -4,15 +4,19 @@ import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
import com.cryptomorin.xseries.messages.ActionBar;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
@@ -41,6 +45,14 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
}
public void sendActionBar(Player player, String... values) {
sendActionBar(player, ParamsUtils.buildParams(this.params, values));
}
public void sendActionBar(Player player, Map<String, Object> placeholders) {
ActionBar.sendActionBar(player, parseString(player, placeholders));
}
@Override
public @NotNull Collection<CommandSender> getAllReceivers() {
List<CommandSender> senders = new ArrayList<>();
@@ -7,8 +7,8 @@ import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import com.cryptomorin.xseries.messages.Titles;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -22,6 +22,8 @@ import java.util.function.Predicate;
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
public static final @NotNull ConfiguredTitle.TitleConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
public static TitleConfigBuilder create() {
return CraftConfigValue.builder().createTitle();
}
@@ -35,7 +37,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build();
}
protected final @NotNull TitleSendConsumer sendConsumer;
protected final @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
protected final @NotNull String[] params;
protected final int fadeIn;
@@ -43,7 +45,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
protected final int fadeOut;
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
@NotNull TitleSendConsumer sendConsumer,
@NotNull ConfiguredTitle.TitleConsumer sendConsumer,
int fadeIn, int stay, int fadeOut) {
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
this.sendConsumer = sendConsumer;
@@ -68,7 +70,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
return fadeOut;
}
public @NotNull TitleSendConsumer getSendConsumer() {
public @NotNull ConfiguredTitle.TitleConsumer getSendConsumer() {
return sendConsumer;
}
@@ -116,4 +118,26 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
return (s, d) -> TitleConfig.deserialize(s);
}
@FunctionalInterface
public interface TitleConsumer {
/**
* 向目标玩家发送标题文字
*
* @param player 目标玩家
* @param fadeIn 淡入时间 (ticks)
* @param stay 保留时间 (ticks)
* @param fadeOut 淡出时间 (ticks)
* @param line1 第一行文字
* @param line2 第二行文字
*/
void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull String line1, @NotNull String line2);
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.6.0</version>
<version>2.8.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -1,15 +1,18 @@
package cc.carm.lib.mineconfiguration.bungee;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.mineconfiguration.bungee.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 {
public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> {
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
@@ -94,4 +97,26 @@ public class MineConfiguration {
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 ConfigurationRoot configRoot,
@NotNull ConfigurationRoot messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
public MineConfiguration(@NotNull Plugin plugin,
@NotNull Class<? extends ConfigurationRoot> configRoot,
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
}
+7 -7
View File
@@ -10,14 +10,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<deps.easyconfifuration.version>3.6.0</deps.easyconfifuration.version>
<deps.easyplugin.version>1.5.4</deps.easyplugin.version>
<deps.easyconfifuration.version>3.8.0</deps.easyconfifuration.version>
<deps.easyplugin.version>1.5.7</deps.easyplugin.version>
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
</properties>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId>
<version>2.6.0</version>
<version>2.8.2</version>
<packaging>pom</packaging>
<modules>
<module>common</module>
@@ -122,7 +122,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
@@ -150,7 +150,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
@@ -178,7 +178,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -225,7 +225,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>