mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af614deae6 | |||
| cf80291e51 | |||
| 53ba56b0ad | |||
| da2023aad0 | |||
| 29526223e4 | |||
| e8044c112e | |||
| a552938858 | |||
| b61baed8bc | |||
| 0cd61842e5 | |||
| 4850514a8a | |||
| 1dca7a2274 | |||
| a02efbf29c | |||
| 352ef107f9 | |||
| 25f005ddfb | |||
| 26922f9225 | |||
| f0957c1b3e | |||
| 7d645f4386 | |||
| 08a56c7168 | |||
| f254383b79 | |||
| be3b7fffad | |||
| d567bfb4af |
@@ -39,7 +39,6 @@ jobs:
|
|||||||
central-deploy:
|
central-deploy:
|
||||||
name: "Deploy Project (Central Repository)"
|
name: "Deploy Project (Central Repository)"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
|
paths-ignore:
|
||||||
|
- ".github/**"
|
||||||
|
- "README.md"
|
||||||
|
- "LICENCE"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
|
### **MineConfiguration-Common**
|
||||||
|
|
||||||
|
全部版本的共用部分,包括
|
||||||
|
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||||
|
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||||
|
|
||||||
|
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||||
|
|
||||||
### **MineConfiguration-CraftBukkit**
|
### **MineConfiguration-CraftBukkit**
|
||||||
|
|
||||||
CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit** 或 **MineConfiguration-Spigot** 。
|
CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit** 或 **MineConfiguration-Spigot** 。
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.2</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -38,6 +38,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.2</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -40,6 +40,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.configuration;
|
package cc.carm.lib.configuration;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.BungeeConfigProvider;
|
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.JsonConfiguration;
|
import net.md_5.bungee.config.JsonConfiguration;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.builder.BungeeConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.bungee.source.BungeeSectionWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
|
public static @NotNull BungeeConfigBuilder builder() {
|
||||||
|
return new BungeeConfigBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BungeeConfigValue(@Nullable BungeeConfigProvider provider,
|
||||||
|
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
||||||
|
super(provider, configPath, comments, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.builder;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||||
|
|
||||||
|
public abstract class AbstractBungeeBuilder<T, B extends AbstractBungeeBuilder<T, B>>
|
||||||
|
extends AbstractConfigBuilder<T, B, BungeeConfigProvider> {
|
||||||
|
|
||||||
|
public AbstractBungeeBuilder() {
|
||||||
|
super(BungeeConfigProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.builder;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageBuilder;
|
||||||
|
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class BungeeConfigBuilder extends ConfigBuilder {
|
||||||
|
|
||||||
|
public @NotNull BungeeMessageBuilder createMessage() {
|
||||||
|
return new BungeeMessageBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.common.utils.ColorParser;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
||||||
|
|
||||||
|
|
||||||
|
public BungeeMessageBuilder() {
|
||||||
|
super(CommandSender.class, MessageText.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.bungee.value.ConfiguredMessageList;
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageListBuilder;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class BungeeMessageListBuilder<M>
|
||||||
|
extends MessageListBuilder<M, CommandSender, MessageText, BungeeMessageListBuilder<M>> {
|
||||||
|
|
||||||
|
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
super(CommandSender.class, MessageText::of, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull BungeeMessageListBuilder<M> getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessageList<M> build() {
|
||||||
|
return new ConfiguredMessageList<>(
|
||||||
|
this.provider, this.path, buildComments(),
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
||||||
|
buildParams(), this.messageParser, this.sendFunction
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.bungee.value.ConfiguredMessage;
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageValueBuilder;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class BungeeMessageValueBuilder<M>
|
||||||
|
extends MessageValueBuilder<M, CommandSender, MessageText, BungeeMessageValueBuilder<M>> {
|
||||||
|
|
||||||
|
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
super(CommandSender.class, MessageText::new, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull BungeeMessageValueBuilder<M> getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
|
return new ConfiguredMessage<>(
|
||||||
|
this.provider, this.path, buildComments(),
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
||||||
|
buildParams(), this.messageParser, this.sendHandler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class MessageText extends AbstractText<CommandSender> {
|
||||||
|
|
||||||
|
public MessageText(@NotNull String message) {
|
||||||
|
super(CommandSender.class, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("!null,-> !null")
|
||||||
|
public static @Nullable MessageText of(@Nullable String message) {
|
||||||
|
if (message == null) return null;
|
||||||
|
else return new MessageText(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
|
||||||
|
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||||
|
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
||||||
|
return of(Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
package cc.carm.lib.configuration.bungee.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
package cc.carm.lib.configuration.bungee.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.BungeeConfigValue;
|
||||||
|
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageValueBuilder;
|
||||||
|
import cc.carm.lib.configuration.bungee.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <M> BungeeMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
|
return BungeeConfigValue.builder().createMessage().asValue(messageParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BungeeMessageValueBuilder<String> asString() {
|
||||||
|
return BungeeConfigValue.builder().createMessage().asStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString() {
|
||||||
|
return asString().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||||
|
return asString().defaults(defaultMessage).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||||
|
super(provider, sectionPath, comments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
|
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
||||||
|
send(ProxyServer.getInstance().getConsole(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
package cc.carm.lib.configuration.bungee.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bungee.BungeeConfigValue;
|
||||||
|
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageListBuilder;
|
||||||
|
import cc.carm.lib.configuration.bungee.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <M> BungeeMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
|
return BungeeConfigValue.builder().createMessage().asList(messageParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BungeeMessageListBuilder<String> asStrings() {
|
||||||
|
return BungeeConfigValue.builder().createMessage().asStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessageList<String> ofStrings(@NotNull String... defaultMessages) {
|
||||||
|
return asStrings().defaults(defaultMessages).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull List<MessageText> messages, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||||
|
super(provider, sectionPath, comments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
|
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
||||||
|
send(ProxyServer.getInstance().getConsole(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?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>1.2.2</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
|
<version>${easyconfiguration.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.themoep</groupId>
|
||||||
|
<artifactId>minedown</artifactId>
|
||||||
|
<version>1.7.1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
<version>1.16-R0.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package cc.carm.lib.configuration.common.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public abstract class MessageConfigBuilder<R, T extends AbstractText<R>> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认的变量格式为 {@code %(变量名)}。
|
||||||
|
*/
|
||||||
|
public static Function<@NotNull String, @NotNull String> DEFAULT_PARAM_FORMATTER = (s) -> "%(" + s + ")";
|
||||||
|
|
||||||
|
protected final @NotNull Class<R> receiverClazz;
|
||||||
|
protected final @NotNull Class<T> textClazz;
|
||||||
|
|
||||||
|
public MessageConfigBuilder(@NotNull Class<R> receiverClazz,
|
||||||
|
@NotNull Class<T> textClazz) {
|
||||||
|
this.receiverClazz = receiverClazz;
|
||||||
|
this.textClazz = textClazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以单条消息为目标,构建一个消息配置。
|
||||||
|
*
|
||||||
|
* @param parser 消息解析器,负责将String转换为目标消息类型。
|
||||||
|
* @param <M> 消息类型
|
||||||
|
* @return 单条消息构建器
|
||||||
|
*/
|
||||||
|
public abstract <M> @NotNull MessageValueBuilder<M, R, T, ?> asValue(@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以多行消息为目标,构建一个消息配置。
|
||||||
|
*
|
||||||
|
* @param parser 消息解析器
|
||||||
|
* @param <M> 消息类型
|
||||||
|
* @return 多行消息构建器
|
||||||
|
*/
|
||||||
|
public abstract <M> @NotNull MessageListBuilder<M, R, T, ?> asList(@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
package cc.carm.lib.configuration.common.builder.message;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
||||||
|
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder.DEFAULT_PARAM_FORMATTER;
|
||||||
|
|
||||||
|
public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B extends MessageListBuilder<M, R, T, B>>
|
||||||
|
extends CommonConfigBuilder<List<T>, B> {
|
||||||
|
|
||||||
|
protected final @NotNull Class<R> receiverClazz;
|
||||||
|
|
||||||
|
protected @NotNull String[] params;
|
||||||
|
protected @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
|
protected @NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction;
|
||||||
|
|
||||||
|
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||||
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
|
public MessageListBuilder(@NotNull Class<R> receiverClazz,
|
||||||
|
@NotNull Function<String, T> textBuilder,
|
||||||
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
||||||
|
this.receiverClazz = receiverClazz;
|
||||||
|
this.textBuilder = textBuilder;
|
||||||
|
this.params = new String[0];
|
||||||
|
this.messageParser = parser;
|
||||||
|
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
|
||||||
|
this.sendFunction = (sender, M) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public B defaults(@NotNull String... messages) {
|
||||||
|
return defaults(new ArrayList<>(Arrays.stream(messages).map(textBuilder).collect(Collectors.toList())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public B params(@NotNull String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B params(@NotNull List<String> params) {
|
||||||
|
this.params = params.toArray(new String[0]);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||||
|
this.paramFormatter = paramFormatter;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B whenSend(@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction) {
|
||||||
|
this.sendFunction = sendFunction;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
||||||
|
|
||||||
|
protected final String[] buildParams() {
|
||||||
|
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package cc.carm.lib.configuration.common.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
||||||
|
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder.DEFAULT_PARAM_FORMATTER;
|
||||||
|
|
||||||
|
public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B extends MessageValueBuilder<M, R, T, B>>
|
||||||
|
extends CommonConfigBuilder<T, B> {
|
||||||
|
|
||||||
|
|
||||||
|
protected final @NotNull Class<R> receiverClazz;
|
||||||
|
protected @NotNull String[] params;
|
||||||
|
protected @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
|
protected @NotNull BiConsumer<@NotNull R, @NotNull M> sendHandler;
|
||||||
|
|
||||||
|
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||||
|
|
||||||
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
|
public MessageValueBuilder(@NotNull Class<R> receiverClazz,
|
||||||
|
@NotNull Function<String, T> textBuilder,
|
||||||
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
||||||
|
this.receiverClazz = receiverClazz;
|
||||||
|
this.params = new String[0];
|
||||||
|
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
|
||||||
|
this.textBuilder = textBuilder;
|
||||||
|
this.messageParser = parser;
|
||||||
|
this.sendHandler = (receiver, M) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public B defaults(@NotNull String message) {
|
||||||
|
return defaults(this.textBuilder.apply(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public B params(@NotNull String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B params(@NotNull List<String> params) {
|
||||||
|
this.params = params.toArray(new String[0]);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||||
|
this.paramFormatter = paramFormatter;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public B whenSend(@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction) {
|
||||||
|
this.sendHandler = sendFunction;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract @NotNull ConfigMessage<M, T, R> build();
|
||||||
|
|
||||||
|
protected final String[] buildParams() {
|
||||||
|
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package cc.carm.lib.configuration.common.data;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param <R> Receiver type
|
||||||
|
*/
|
||||||
|
public abstract class AbstractText<R> {
|
||||||
|
|
||||||
|
private final @NotNull Class<R> receiverClazz;
|
||||||
|
protected @NotNull String message;
|
||||||
|
|
||||||
|
public AbstractText(@NotNull Class<R> receiverClazz, @NotNull String message) {
|
||||||
|
this.receiverClazz = receiverClazz;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Class<R> getReceiverClazz() {
|
||||||
|
return receiverClazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getMessage() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
|
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
return parse(parser, receiver, buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
|
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
|
String message = getMessage();
|
||||||
|
if (message.isEmpty()) return null; // No further processing
|
||||||
|
else return parser.apply(receiver, setPlaceholders(message, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> buildParams(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
if (params == null || params.length == 0) return map;
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
|
map.put(params[i], values.length > i ? values[i] : "?");
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@NotNull String messages, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (messages.isEmpty()) return messages;
|
||||||
|
|
||||||
|
String parsed = messages;
|
||||||
|
for (Map.Entry<String, Object> entry : placeholders.entrySet()) {
|
||||||
|
Object value = entry.getValue();
|
||||||
|
parsed = parsed.replace(entry.getKey(), value == null ? "" : value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package cc.carm.lib.configuration.common.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ColorParser {
|
||||||
|
|
||||||
|
public static String parse(String text) {
|
||||||
|
return parseBaseColor(parseHexColor(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] parse(String... texts) {
|
||||||
|
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parse(List<String> texts) {
|
||||||
|
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String parseBaseColor(final String text) {
|
||||||
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse HEXColor code like <blockquote><pre>&(#000000)</pre></blockquote> to minecraft colored text.
|
||||||
|
*
|
||||||
|
* @param text the text to parse
|
||||||
|
* @return color parsed
|
||||||
|
*/
|
||||||
|
public static String parseHexColor(String text) {
|
||||||
|
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
||||||
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
||||||
|
hexColor = hexColor.replace("&", "");
|
||||||
|
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
||||||
|
for (int i = 1; i < hexColor.length(); i++) {
|
||||||
|
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
||||||
|
}
|
||||||
|
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
||||||
|
matcher.reset(text);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package cc.carm.lib.configuration.common.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||||
|
extends ConfiguredValue<T> {
|
||||||
|
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
|
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction;
|
||||||
|
|
||||||
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
|
public ConfigMessage(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
||||||
|
@NotNull Function<String, T> textBuilder) {
|
||||||
|
super(provider, sectionPath, comments, textClazz, defaultMessage,
|
||||||
|
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
||||||
|
);
|
||||||
|
this.params = params;
|
||||||
|
this.messageParser = messageParser;
|
||||||
|
this.sendFunction = sendFunction;
|
||||||
|
this.textBuilder = textBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
||||||
|
return parse(sender, AbstractText.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
|
T value = get();
|
||||||
|
if (value == null || value.getMessage().isEmpty()) return null;
|
||||||
|
else return value.parse(this.messageParser, sender, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||||
|
send(receiver, AbstractText.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (receiver == null) return;
|
||||||
|
M parsed = parse(receiver, placeholders);
|
||||||
|
if (parsed == null) return;
|
||||||
|
sendFunction.accept(receiver, parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(@Nullable Object... values) {
|
||||||
|
broadcast(AbstractText.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||||
|
|
||||||
|
public void set(@Nullable String value) {
|
||||||
|
this.set(value == null ? null : buildText(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected T buildText(String value) {
|
||||||
|
return textBuilder.apply(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package cc.carm.lib.configuration.common.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends ConfiguredList<T> {
|
||||||
|
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
|
protected final @NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction;
|
||||||
|
|
||||||
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
||||||
|
@NotNull Function<String, @NotNull T> textBuilder) {
|
||||||
|
super(
|
||||||
|
provider, sectionPath, comments, textClazz, messages,
|
||||||
|
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
||||||
|
);
|
||||||
|
this.params = params;
|
||||||
|
this.messageParser = messageParser;
|
||||||
|
this.sendFunction = sendFunction;
|
||||||
|
this.textBuilder = textBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable List<M> parse(@Nullable R sender, @Nullable Object... values) {
|
||||||
|
return parse(sender, T.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable List<M> parse(@Nullable R sender, @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;
|
||||||
|
|
||||||
|
return list.stream().map(value -> value.parse(this.messageParser, sender, placeholders))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||||
|
send(receiver, T.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (receiver == null) return;
|
||||||
|
List<M> parsed = parse(receiver, placeholders);
|
||||||
|
if (parsed == null) return;
|
||||||
|
sendFunction.accept(receiver, parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(@Nullable Object... values) {
|
||||||
|
broadcast(T.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||||
|
|
||||||
|
public void setMessages(@NotNull String... values) {
|
||||||
|
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessages(@Nullable List<String> values) {
|
||||||
|
if (values == null || values.isEmpty()) {
|
||||||
|
set(null);
|
||||||
|
} else {
|
||||||
|
set(buildText(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<T> buildText(List<String> values) {
|
||||||
|
return values.stream().map(textBuilder).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+15
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.2</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -24,6 +24,13 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
@@ -31,6 +38,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+5
@@ -2,6 +2,7 @@ package cc.carm.lib.configuration.craft.builder;
|
|||||||
|
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.builder.message.CraftMessageBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
||||||
@@ -20,6 +21,10 @@ public class CraftConfigBuilder extends ConfigBuilder {
|
|||||||
return new ItemConfigBuilder();
|
return new ItemConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull CraftMessageBuilder createMessage() {
|
||||||
|
return new CraftMessageBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
||||||
return new SerializableBuilder<>(valueClass);
|
return new SerializableBuilder<>(valueClass);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -31,7 +31,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
|
|
||||||
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
||||||
@Nullable String name, @NotNull List<String> lore) {
|
@Nullable String name, @NotNull List<String> lore) {
|
||||||
return defaults(new ItemConfig(type, data, name, lore));
|
return defaultType(type).defaultDataID(data).defaultName(name).defaultLore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemConfigBuilder defaultType(@NotNull Material type) {
|
public ItemConfigBuilder defaultType(@NotNull Material type) {
|
||||||
@@ -39,7 +39,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemConfigBuilder defaultName(@NotNull String name) {
|
public ItemConfigBuilder defaultName(@Nullable String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,11 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemConfigBuilder defaultLore(@NotNull String... lore) {
|
public ItemConfigBuilder defaultLore(@NotNull String... lore) {
|
||||||
this.lore = new ArrayList<>(Arrays.asList(lore));
|
return defaultLore(Arrays.asList(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfigBuilder defaultLore(@NotNull List<String> lore) {
|
||||||
|
this.lore = new ArrayList<>(lore);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.common.utils.ColorParser;
|
||||||
|
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.craft.utils.PAPIHelper;
|
||||||
|
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.function.BiFunction;
|
||||||
|
|
||||||
|
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
||||||
|
|
||||||
|
|
||||||
|
public CraftMessageBuilder() {
|
||||||
|
super(CommandSender.class, MessageText.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <M> CraftMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
return new CraftMessageValueBuilder<>(parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <M> CraftMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
return new CraftMessageListBuilder<>(parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull
|
||||||
|
CraftMessageValueBuilder<String> asStringValue() {
|
||||||
|
return asValue(defaultParser()).whenSend(CommandSender::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull
|
||||||
|
CraftMessageListBuilder<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) -> {
|
||||||
|
if (receiver instanceof Player && hasPlaceholderAPI()) {
|
||||||
|
message = PAPIHelper.parseMessages((Player) receiver, message);
|
||||||
|
}
|
||||||
|
return ColorParser.parse(message);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlaceholderAPI() {
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageListBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.craft.value.ConfiguredMessageList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class CraftMessageListBuilder<M>
|
||||||
|
extends MessageListBuilder<M, CommandSender, MessageText, CraftMessageListBuilder<M>> {
|
||||||
|
|
||||||
|
public CraftMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
super(CommandSender.class, MessageText::of, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull CraftMessageListBuilder<M> getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessageList<M> build() {
|
||||||
|
return new ConfiguredMessageList<>(
|
||||||
|
this.provider, this.path, buildComments(),
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
||||||
|
buildParams(), this.messageParser, this.sendFunction
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.builder.message.MessageValueBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||||
|
import cc.carm.lib.configuration.craft.value.ConfiguredMessage;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class CraftMessageValueBuilder<M>
|
||||||
|
extends MessageValueBuilder<M, CommandSender, MessageText, CraftMessageValueBuilder<M>> {
|
||||||
|
|
||||||
|
public CraftMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
|
super(CommandSender.class, MessageText::new, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull CraftMessageValueBuilder<M> getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
|
return new ConfiguredMessage<>(
|
||||||
|
this.provider, this.path, buildComments(),
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
||||||
|
buildParams(), this.messageParser, this.sendHandler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
package cc.carm.lib.configuration.craft.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.utils.ColorParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.craft.utils.PAPIHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -15,10 +19,10 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class ItemConfig {
|
public class ItemConfig {
|
||||||
|
|
||||||
@NotNull Material type;
|
protected @NotNull Material type;
|
||||||
short data;
|
protected short data;
|
||||||
@Nullable String name;
|
protected @Nullable String name;
|
||||||
@NotNull List<String> lore;
|
protected @NotNull List<String> lore;
|
||||||
|
|
||||||
public ItemConfig(@NotNull Material type, short damage,
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
@Nullable String name, @NotNull List<String> lore) {
|
@Nullable String name, @NotNull List<String> lore) {
|
||||||
@@ -44,21 +48,28 @@ public class ItemConfig {
|
|||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack() {
|
public final @NotNull ItemStack getItemStack() {
|
||||||
return getItemStack(1);
|
return getItemStack(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack(int amount) {
|
public @NotNull ItemStack getItemStack(int amount) {
|
||||||
|
return getItemStack(null, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
||||||
|
return getItemStack(player, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount) {
|
||||||
ItemStack item = new ItemStack(type, amount, data);
|
ItemStack item = new ItemStack(type, amount, data);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta == null) return item;
|
if (meta == null) return item;
|
||||||
if (getName() != null) meta.setDisplayName(getName());
|
if (getName() != null) meta.setDisplayName(parseName(player, getName()));
|
||||||
if (!getLore().isEmpty()) meta.setLore(getLore());
|
if (!getLore().isEmpty()) meta.setLore(parseLore(player, getLore()));
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public @NotNull Map<String, Object> serialize() {
|
public @NotNull Map<String, Object> serialize() {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("type", type.name());
|
map.put("type", type.name());
|
||||||
@@ -70,7 +81,7 @@ public class ItemConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
||||||
String typeName = section.getString("name");
|
String typeName = section.getString("type");
|
||||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||||
|
|
||||||
Material type = Material.matchMaterial(typeName);
|
Material type = Material.matchMaterial(typeName);
|
||||||
@@ -89,4 +100,20 @@ public class ItemConfig {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static @NotNull String parseName(@Nullable Player player, String message) {
|
||||||
|
if (player != null && hasPlaceholderAPI()) message = PAPIHelper.parseMessages(player, message);
|
||||||
|
return ColorParser.parse(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static @NotNull List<String> parseLore(@Nullable Player player, List<String> messages) {
|
||||||
|
if (player != null && hasPlaceholderAPI()) messages = PAPIHelper.parseMessages(player, messages);
|
||||||
|
return ColorParser.parse(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlaceholderAPI() {
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.data.AbstractText;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class MessageText extends AbstractText<CommandSender> {
|
||||||
|
|
||||||
|
public MessageText(@NotNull String message) {
|
||||||
|
super(CommandSender.class, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("!null,-> !null")
|
||||||
|
public static @Nullable MessageText of(@Nullable String message) {
|
||||||
|
if (message == null) return null;
|
||||||
|
else return new MessageText(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
|
||||||
|
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||||
|
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
||||||
|
return of(Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ColorParser {
|
||||||
|
|
||||||
|
public static String parse(String text) {
|
||||||
|
text = parseHexColor(text);
|
||||||
|
return parseColor(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] parse(String... texts) {
|
||||||
|
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parse(List<String> texts) {
|
||||||
|
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String parseColor(final String text) {
|
||||||
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse HEXColor code like <blockquote><pre>&(#000000)</pre></blockquote> to minecraft colored text.
|
||||||
|
*
|
||||||
|
* @param text the text to parse
|
||||||
|
* @return color parsed
|
||||||
|
*/
|
||||||
|
public static String parseHexColor(String text) {
|
||||||
|
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
||||||
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
||||||
|
hexColor = hexColor.replace("&", "");
|
||||||
|
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
||||||
|
for (int i = 1; i < hexColor.length(); i++) {
|
||||||
|
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
||||||
|
}
|
||||||
|
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
||||||
|
matcher.reset(text);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.utils;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PAPIHelper {
|
||||||
|
|
||||||
|
public static String parseMessages(Player player, String message) {
|
||||||
|
return PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parseMessages(Player player, List<String> messages) {
|
||||||
|
return PlaceholderAPI.setPlaceholders(player, messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
|||||||
public static ItemConfigBuilder create() {
|
public static ItemConfigBuilder create() {
|
||||||
return CraftConfigValue.builder().createItem();
|
return CraftConfigValue.builder().createItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfiguredItem of() {
|
public static ConfiguredItem of() {
|
||||||
return CraftConfigValue.builder().ofItem();
|
return CraftConfigValue.builder().ofItem();
|
||||||
}
|
}
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||||
|
import cc.carm.lib.configuration.craft.builder.message.CraftMessageValueBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <M> CraftMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
|
return CraftConfigValue.builder().createMessage().asValue(messageParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftMessageValueBuilder<String> asString() {
|
||||||
|
return CraftConfigValue.builder().createMessage().asStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString() {
|
||||||
|
return asString().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||||
|
return asString().defaults(defaultMessage).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||||
|
super(provider, sectionPath, comments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||||
|
send(Bukkit.getConsoleSender(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||||
|
import cc.carm.lib.configuration.craft.builder.message.CraftMessageListBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <M> CraftMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
|
return CraftConfigValue.builder().createMessage().asList(messageParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftMessageListBuilder<String> asStrings() {
|
||||||
|
return CraftConfigValue.builder().createMessage().asStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessageList<String> ofStrings(@NotNull String... defaultMessages) {
|
||||||
|
return asStrings().defaults(defaultMessages).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@NotNull List<MessageText> messages, @NotNull String[] params,
|
||||||
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||||
|
super(provider, sectionPath, comments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||||
|
send(Bukkit.getConsoleSender(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
<module>craftbukkit</module>
|
<module>craftbukkit</module>
|
||||||
<module>bukkit</module>
|
<module>bukkit</module>
|
||||||
<module>spigot</module>
|
<module>spigot</module>
|
||||||
|
<module>common</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.2.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>MineConfiguration</name>
|
<name>MineConfiguration</name>
|
||||||
@@ -70,6 +71,11 @@
|
|||||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>minebench-repo</id>
|
||||||
|
<url>https://repo.minebench.de/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>nexus</id>
|
<id>nexus</id>
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||||
@@ -174,6 +180,9 @@
|
|||||||
<dependencySourceIncludes>
|
<dependencySourceIncludes>
|
||||||
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
|
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
|
||||||
</dependencySourceIncludes>
|
</dependencySourceIncludes>
|
||||||
|
<additionalOptions>
|
||||||
|
<additionalOption>-Xdoclint:none</additionalOption>
|
||||||
|
</additionalOptions>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.2</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -38,6 +38,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user