mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1cebe8daca | |||
| 49df2ca24e | |||
| 6e1803fb75 | |||
| 480f015a2f | |||
| bf5c6a2fce | |||
| f86229037d | |||
| 38292052f5 | |||
| b737e4dda2 | |||
| 058da094cd | |||
| 020adeb030 | |||
| 3183e1025d | |||
| 3c57b97fb1 | |||
| c77253508c | |||
| 56ee1ec991 | |||
| 706db18ffe | |||
| 46bfbe063e | |||
| c3d993311e | |||
| 67d1fd67fc | |||
| 357b6054a4 | |||
| c150d607e9 | |||
| dbcaff5c93 | |||
| e0d5f9229b | |||
| caf92ef565 | |||
| 77547cdc80 | |||
| 5d55ddbce9 | |||
| c73032266d | |||
| a6b6d46be6 |
+1
-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>2.8.6</version>
|
<version>2.9.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common;
|
package cc.carm.lib.mineconfiguration.common;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
import cc.carm.lib.configuration.core.Configuration;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -14,19 +14,19 @@ public abstract class AbstractConfiguration<P extends ConfigurationProvider<?>>
|
|||||||
this.messageProvider = messageProvider;
|
this.messageProvider = messageProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeConfig(@NotNull ConfigurationRoot configRoot) {
|
public void initializeConfig(@NotNull Configuration configRoot) {
|
||||||
this.configProvider.initialize(configRoot);
|
this.configProvider.initialize(configRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMessage(@NotNull ConfigurationRoot messageRoot) {
|
public void initializeMessage(@NotNull Configuration messageRoot) {
|
||||||
this.messageProvider.initialize(messageRoot);
|
this.messageProvider.initialize(messageRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeConfig(@NotNull Class<? extends ConfigurationRoot> configRoot) {
|
public void initializeConfig(@NotNull Class<? extends Configuration> configRoot) {
|
||||||
this.configProvider.initialize(configRoot);
|
this.configProvider.initialize(configRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMessage(@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
public void initializeMessage(@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
this.messageProvider.initialize(messageRoot);
|
this.messageProvider.initialize(messageRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ public class PreparedMessage<R, M> {
|
|||||||
*
|
*
|
||||||
* @param receivers 消息的接收者们
|
* @param receivers 消息的接收者们
|
||||||
*/
|
*/
|
||||||
public void to(@NotNull Iterable<R> receivers) {
|
public void to(@NotNull Iterable<? extends R> receivers) {
|
||||||
receivers.forEach(this::to);
|
receivers.forEach(this::to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>2.8.6</version>
|
<version>2.9.2</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cryptomorin</groupId>
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
<artifactId>XSeries</artifactId>
|
<artifactId>XSeries</artifactId>
|
||||||
<version>9.6.0</version>
|
<version>9.8.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.4</version>
|
<version>2.11.5</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -1,5 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit;
|
package cc.carm.lib.mineconfiguration.bukkit;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.Configuration;
|
||||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
||||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
@@ -48,16 +49,16 @@ public class MineConfiguration extends AbstractConfiguration<BukkitConfigProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MineConfiguration(@NotNull JavaPlugin plugin,
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
@NotNull ConfigurationRoot configRoot,
|
@NotNull Configuration configRoot,
|
||||||
@NotNull ConfigurationRoot messageRoot) {
|
@NotNull Configuration messageRoot) {
|
||||||
this(plugin);
|
this(plugin);
|
||||||
initializeConfig(configRoot);
|
initializeConfig(configRoot);
|
||||||
initializeMessage(messageRoot);
|
initializeMessage(messageRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MineConfiguration(@NotNull JavaPlugin plugin,
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
this(plugin);
|
this(plugin);
|
||||||
initializeConfig(configRoot);
|
initializeConfig(configRoot);
|
||||||
initializeMessage(messageRoot);
|
initializeMessage(messageRoot);
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.builder.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.ConfiguredNotify;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.DefaultNotifyTypes;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
public class NotifyConfigBuilder extends CommonConfigBuilder<List<NotifyConfig>, NotifyConfigBuilder> {
|
||||||
|
|
||||||
|
protected final @NotNull List<NotifyConfig> notifications = new ArrayList<>();
|
||||||
|
|
||||||
|
protected @NotNull String[] params = new String[0];
|
||||||
|
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||||
|
|
||||||
|
public NotifyConfigBuilder() {
|
||||||
|
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultMessages(@NotNull String... messages) {
|
||||||
|
return defaultMessages(Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultMessages(@NotNull List<String> messages) {
|
||||||
|
for (String message : messages) {
|
||||||
|
notifications.add(NotifyConfig.of(DefaultNotifyTypes.MESSAGE, message));
|
||||||
|
}
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultActionBar(@NotNull String message) {
|
||||||
|
notifications.add(NotifyConfig.of(DefaultNotifyTypes.ACTIONBAR, message));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
return defaultSound(sound.name(), volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull Sound sound, float volume) {
|
||||||
|
return defaultSound(sound, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull Sound sound) {
|
||||||
|
return defaultSound(sound, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull String soundName, float volume, float pitch) {
|
||||||
|
notifications.add(NotifyConfig.of(DefaultNotifyTypes.SOUND, new SoundConfig(soundName, volume, pitch)));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull String soundName, float volume) {
|
||||||
|
return defaultSound(soundName, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultSound(@NotNull String soundName) {
|
||||||
|
return defaultSound(soundName, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultTitle(@Nullable String line1, @Nullable String line2,
|
||||||
|
@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) {
|
||||||
|
notifications.add(NotifyConfig.of(DefaultNotifyTypes.TITLE, TitleConfig.of(line1, line2, fadeIn, stay, fadeOut)));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder defaultTitle(@Nullable String line1, @Nullable String line2) {
|
||||||
|
return defaultTitle(line1, line2, 10, 60, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder params(String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyConfigBuilder params(@NotNull List<String> params) {
|
||||||
|
return params(params.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public NotifyConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
|
||||||
|
this.paramFormatter = paramFormatter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull NotifyConfigBuilder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredNotify build() {
|
||||||
|
return new ConfiguredNotify(buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyCache;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class NotifyConfig {
|
||||||
|
|
||||||
|
public static @Nullable NotifyConfig deserialize(@NotNull String config) {
|
||||||
|
return Optional.ofNullable(NotifyCache.deserialize(config)).map(NotifyConfig::of).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull NotifyConfig of(@NotNull NotifyCache<?, ?> cache) {
|
||||||
|
return new NotifyConfig(cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable NotifyConfig of(@NotNull String key, @Nullable String param, @Nullable String content) {
|
||||||
|
return Optional.ofNullable(NotifyCache.of(key, param, content)).map(NotifyConfig::of).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable String param, @Nullable String content) {
|
||||||
|
return of(type, type.parseMeta(param, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable M meta) {
|
||||||
|
return of(NotifyCache.of(type, meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull NotifyCache<?, ?> cache;
|
||||||
|
|
||||||
|
|
||||||
|
public NotifyConfig(@NotNull NotifyCache<?, ?> cache) {
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull NotifyCache<?, ?> getCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
getCache().execute(player, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serialize() {
|
||||||
|
return getCache().serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+24
@@ -58,6 +58,30 @@ public class TitleConfig {
|
|||||||
this.fadeOut = fadeOut;
|
this.fadeOut = fadeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getFadeIn() {
|
||||||
|
return fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFadeOut() {
|
||||||
|
return fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStay() {
|
||||||
|
return stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStandardTime() {
|
||||||
|
return this.fadeIn == 10 && this.stay == 60 && this.fadeOut == 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable TextConfig getLine1() {
|
||||||
|
return line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable TextConfig getLine2() {
|
||||||
|
return line2;
|
||||||
|
}
|
||||||
|
|
||||||
public void send(@NotNull Player player,
|
public void send(@NotNull Player player,
|
||||||
@NotNull Map<String, Object> placeholders,
|
@NotNull Map<String, Object> placeholders,
|
||||||
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||||
|
|||||||
+3
@@ -7,6 +7,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class PlaceholderAPIHelper {
|
public class PlaceholderAPIHelper {
|
||||||
|
|
||||||
|
private PlaceholderAPIHelper() {
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseMessages(Player player, String message) {
|
public static String parseMessages(Player player, String message) {
|
||||||
try {
|
try {
|
||||||
return PlaceholderAPI.setPlaceholders(player, message);
|
return PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
|||||||
+3
@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class TextParser {
|
public class TextParser {
|
||||||
|
|
||||||
|
private TextParser() {
|
||||||
|
}
|
||||||
|
|
||||||
@Contract("_,!null,_->!null")
|
@Contract("_,!null,_->!null")
|
||||||
public static @Nullable String parseText(@Nullable CommandSender sender, @Nullable String message, @NotNull Map<String, Object> placeholders) {
|
public static @Nullable String parseText(@Nullable CommandSender sender, @Nullable String message, @NotNull Map<String, Object> placeholders) {
|
||||||
if (message == null) return null;
|
if (message == null) return null;
|
||||||
|
|||||||
+273
@@ -0,0 +1,273 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
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.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public abstract class ItemModifier<S extends ItemModifier<S, R>, R> {
|
||||||
|
|
||||||
|
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^(?:\\{(.*)})?#(.*)#(?:\\{(-?\\d+)(?:,(-?\\d+))?})?$");
|
||||||
|
|
||||||
|
protected final @NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider;
|
||||||
|
|
||||||
|
protected @NotNull Map<String, Object> placeholders = new HashMap<>();
|
||||||
|
protected @NotNull String[] params;
|
||||||
|
protected @NotNull Object[] values;
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, LoreContent<?>> insertLore = new HashMap<>();
|
||||||
|
|
||||||
|
protected @NotNull BiConsumer<ItemStack, Player> itemConsumer;
|
||||||
|
protected @NotNull BiConsumer<ItemMeta, Player> metaConsumer;
|
||||||
|
|
||||||
|
protected ItemModifier(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
|
this.itemProvider = itemProvider;
|
||||||
|
this.params = new String[0];
|
||||||
|
this.values = new Object[0];
|
||||||
|
itemConsumer = (item, player) -> {
|
||||||
|
};
|
||||||
|
metaConsumer = (meta, player) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract @NotNull S getThis();
|
||||||
|
|
||||||
|
public abstract @Nullable R get(Player player);
|
||||||
|
|
||||||
|
public void applyTo(@Nullable ItemStack item, @Nullable Player player) {
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return;
|
||||||
|
|
||||||
|
Map<String, Object> finalPlaceholders = buildPlaceholders();
|
||||||
|
|
||||||
|
String name = meta.getDisplayName();
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
meta.setDisplayName(TextParser.parseText(player, name, finalPlaceholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> parsedLore = parseLore(player, meta.getLore(), insertLore, finalPlaceholders);
|
||||||
|
if (!parsedLore.isEmpty()) {
|
||||||
|
meta.setLore(parsedLore);
|
||||||
|
}
|
||||||
|
|
||||||
|
metaConsumer.accept(meta, player);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
itemConsumer.accept(item, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
||||||
|
this.metaConsumer = this.metaConsumer.andThen(modifier);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
||||||
|
this.itemConsumer = this.itemConsumer.andThen(modifier);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S params(String[] params) {
|
||||||
|
this.params = params;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S values(Object... values) {
|
||||||
|
this.values = values;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S placeholders(@NotNull Map<String, Object> placeholders) {
|
||||||
|
this.placeholders = placeholders;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S placeholders(@NotNull Consumer<Map<String, Object>> consumer) {
|
||||||
|
Map<String, Object> placeholders = new HashMap<>();
|
||||||
|
consumer.accept(placeholders);
|
||||||
|
return placeholders(placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path, @NotNull LoreContent<?> content) {
|
||||||
|
insertLore.put(path, content);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path, @NotNull List<String> content) {
|
||||||
|
return insertLore(path, content, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path, @NotNull List<String> content, boolean original) {
|
||||||
|
return insertLore(path, LoreContent.of(content, original));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path, @NotNull String... content) {
|
||||||
|
return insertLore(path, Arrays.asList(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path, @NotNull ConfiguredList<String> content) {
|
||||||
|
return insertLore(path, content.copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path,
|
||||||
|
@NotNull ConfiguredMessage<String> content, @NotNull Object... params) {
|
||||||
|
return insertLore(path, new LoreContent<ConfiguredMessage<String>>(content, false) {
|
||||||
|
@Override
|
||||||
|
public List<String> parse(CommandSender receiver) {
|
||||||
|
String str = getSource().parse(receiver, params);
|
||||||
|
if (str == null || str.isEmpty()) return Collections.emptyList();
|
||||||
|
return Collections.singletonList(str);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insertLore(@NotNull String path,
|
||||||
|
@NotNull ConfiguredMessageList<String> content, @NotNull Object... params) {
|
||||||
|
return insertLore(path, new LoreContent<ConfiguredMessageList<String>>(content, false) {
|
||||||
|
@Override
|
||||||
|
public List<String> parse(CommandSender receiver) {
|
||||||
|
List<String> list = getSource().parse(receiver, params);
|
||||||
|
if (list == null || list.isEmpty()) return Collections.emptyList();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public S amount(int amount) {
|
||||||
|
return handleItem((item, player) -> item.setAmount(amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e) {
|
||||||
|
return addEnchantment(e, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e, int level) {
|
||||||
|
return addEnchantment(e, level, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e, int level, boolean ignoreLevelRestriction) {
|
||||||
|
return handleMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addItemFlags(ItemFlag... flags) {
|
||||||
|
return handleMeta((meta, player) -> meta.addItemFlags(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S glow() {
|
||||||
|
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner 玩家名
|
||||||
|
* @return this
|
||||||
|
* @deprecated Use {@link #setSkullOwner(OfflinePlayer)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public S setSkullOwner(String owner) {
|
||||||
|
return handleMeta((meta, player) -> {
|
||||||
|
if (!(meta instanceof SkullMeta)) return;
|
||||||
|
SkullMeta skullMeta = (SkullMeta) meta;
|
||||||
|
skullMeta.setOwner(owner);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public S setSkullOwner(UUID owner) {
|
||||||
|
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S setSkullOwner(OfflinePlayer owner) {
|
||||||
|
return handleMeta((meta, player) -> {
|
||||||
|
if (!(meta instanceof SkullMeta)) return;
|
||||||
|
SkullMeta skullMeta = (SkullMeta) meta;
|
||||||
|
skullMeta.setOwningPlayer(owner);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Map<String, Object> buildPlaceholders() {
|
||||||
|
Map<String, Object> finalPlaceholders = new HashMap<>();
|
||||||
|
finalPlaceholders.putAll(ParamsUtils.buildParams(params, values));
|
||||||
|
finalPlaceholders.putAll(this.placeholders);
|
||||||
|
return finalPlaceholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parseLore(@Nullable Player player, @Nullable List<String> lore,
|
||||||
|
@NotNull Map<String, LoreContent<?>> insertedLore,
|
||||||
|
@NotNull Map<String, Object> placeholders) {
|
||||||
|
List<String> parsedLore = new ArrayList<>();
|
||||||
|
if (lore == null || lore.isEmpty()) return parsedLore;
|
||||||
|
|
||||||
|
for (String line : lore) {
|
||||||
|
Matcher matcher = LORE_INSERT_PATTERN.matcher(line);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
parsedLore.add(TextParser.parseText(player, line, placeholders));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String path = matcher.group(2);
|
||||||
|
LoreContent<?> content = insertedLore.get(path);
|
||||||
|
if (content == null) continue;
|
||||||
|
|
||||||
|
String prefix = Optional.ofNullable(matcher.group(1))
|
||||||
|
.map(s -> TextParser.parseText(player, s, placeholders))
|
||||||
|
.orElse("");
|
||||||
|
int offset1 = Optional.ofNullable(matcher.group(3))
|
||||||
|
.map(Integer::parseInt).orElse(0);
|
||||||
|
Integer offset2 = Optional.ofNullable(matcher.group(4))
|
||||||
|
.map(Integer::parseInt).orElse(null);
|
||||||
|
|
||||||
|
List<String> inserted = parseLoreLine(
|
||||||
|
player, content, placeholders, prefix,
|
||||||
|
offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2
|
||||||
|
);
|
||||||
|
|
||||||
|
if (content.isOriginal()) {
|
||||||
|
parsedLore.addAll(inserted);
|
||||||
|
} else {
|
||||||
|
parsedLore.addAll(TextParser.parseList(player, inserted, placeholders));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsedLore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent<?> content,
|
||||||
|
@NotNull Map<String, Object> placeholders,
|
||||||
|
@NotNull String parsedPrefix, int upOffset, int downOffset) {
|
||||||
|
List<String> lore = content.parse(player);
|
||||||
|
if (lore.isEmpty()) return Collections.emptyList();
|
||||||
|
|
||||||
|
upOffset = Math.max(0, upOffset);
|
||||||
|
downOffset = Math.max(0, downOffset);
|
||||||
|
|
||||||
|
List<String> finalLore = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < upOffset; i++) finalLore.add(" ");
|
||||||
|
if (content.isOriginal()) {
|
||||||
|
lore.stream().map(s -> parsedPrefix + s).forEach(finalLore::add);
|
||||||
|
} else {
|
||||||
|
lore.stream().map(s -> parsedPrefix + TextParser.parseText(player, s, placeholders)).forEach(finalLore::add);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < downOffset; i++) finalLore.add(" ");
|
||||||
|
|
||||||
|
return finalLore;
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-10
@@ -1,32 +1,39 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LoreContent {
|
public abstract class LoreContent<S> {
|
||||||
|
|
||||||
public static LoreContent of(@NotNull List<String> content) {
|
public static LoreContent<List<String>> of(@NotNull List<String> content) {
|
||||||
return of(content, false);
|
return of(content, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LoreContent of(@NotNull List<String> content, boolean original) {
|
public static LoreContent<List<String>> of(@NotNull List<String> content, boolean original) {
|
||||||
return new LoreContent(content, original);
|
return new LoreContent<List<String>>(content, original) {
|
||||||
|
@Override
|
||||||
|
public List<String> parse(CommandSender receiver) {
|
||||||
|
return getSource();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final @NotNull List<String> content;
|
protected final @NotNull S source;
|
||||||
protected final boolean original;
|
protected final boolean original;
|
||||||
|
|
||||||
public LoreContent(@NotNull List<String> content, boolean original) {
|
public LoreContent(@NotNull S source, boolean original) {
|
||||||
this.content = content;
|
this.source = source;
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull S getSource() {
|
||||||
public @NotNull List<String> getContent() {
|
return source;
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract List<String> parse(CommandSender receiver);
|
||||||
|
|
||||||
public boolean isOriginal() {
|
public boolean isOriginal() {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-239
@@ -1,31 +1,13 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class PreparedItem {
|
public class PreparedItem extends ItemModifier<PreparedItem, ItemStack> {
|
||||||
|
|
||||||
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^(?:\\{(.*)})?#(.*)#(?:\\{(-?\\d+)(?:,(-?\\d+))?})?$");
|
|
||||||
|
|
||||||
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
return new PreparedItem(itemProvider);
|
return new PreparedItem(itemProvider);
|
||||||
@@ -35,236 +17,21 @@ public class PreparedItem {
|
|||||||
return of(player -> item);
|
return of(player -> item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final @NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider;
|
public PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
|
super(itemProvider);
|
||||||
protected @NotNull Map<String, Object> placeholders = new HashMap<>();
|
|
||||||
protected @NotNull String[] params;
|
|
||||||
protected @NotNull Object[] values;
|
|
||||||
|
|
||||||
protected final @NotNull Map<String, LoreContent> insertLore = new HashMap<>();
|
|
||||||
|
|
||||||
protected @NotNull BiConsumer<ItemStack, Player> itemModifier;
|
|
||||||
protected @NotNull BiConsumer<ItemMeta, Player> metaModifier;
|
|
||||||
|
|
||||||
protected PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
|
||||||
this.itemProvider = itemProvider;
|
|
||||||
this.params = new String[0];
|
|
||||||
this.values = new Object[0];
|
|
||||||
itemModifier = (item, player) -> {
|
|
||||||
};
|
|
||||||
metaModifier = (meta, player) -> {
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack get(Player player) {
|
public @Nullable ItemStack get(Player player) {
|
||||||
@Nullable ItemStack item = itemProvider.apply(player);
|
@Nullable ItemStack item = itemProvider.apply(player);
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
applyTo(item, player);
|
||||||
if (meta == null) return item;
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> finalPlaceholders = buildPlaceholders();
|
|
||||||
|
|
||||||
String name = meta.getDisplayName();
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
meta.setDisplayName(TextParser.parseText(player, name, finalPlaceholders));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> parsedLore = parseLore(player, meta.getLore(), insertLore, finalPlaceholders);
|
|
||||||
if (!parsedLore.isEmpty()) {
|
|
||||||
meta.setLore(parsedLore);
|
|
||||||
}
|
|
||||||
|
|
||||||
metaModifier.accept(meta, player);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
itemModifier.accept(item, player);
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedItem handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
@Override
|
||||||
this.metaModifier = this.metaModifier.andThen(modifier);
|
public @NotNull PreparedItem getThis() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedItem handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
|
||||||
this.itemModifier = this.itemModifier.andThen(modifier);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem params(String[] params) {
|
|
||||||
this.params = params;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem values(Object... values) {
|
|
||||||
this.values = values;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem placeholders(@NotNull Map<String, Object> placeholders) {
|
|
||||||
this.placeholders = placeholders;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem placeholders(@NotNull Consumer<Map<String, Object>> consumer) {
|
|
||||||
Map<String, Object> placeholders = new HashMap<>();
|
|
||||||
consumer.accept(placeholders);
|
|
||||||
return placeholders(placeholders);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path, @NotNull LoreContent content) {
|
|
||||||
insertLore.put(path, content);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path, @NotNull List<String> content) {
|
|
||||||
return insertLore(path, content, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path, @NotNull List<String> content, boolean original) {
|
|
||||||
return insertLore(path, LoreContent.of(content, original));
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path, @NotNull String... content) {
|
|
||||||
return insertLore(path, Arrays.asList(content));
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path, @NotNull ConfiguredList<String> content) {
|
|
||||||
return insertLore(path, content.copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path,
|
|
||||||
@NotNull ConfiguredMessage<String> content, @NotNull Object... params) {
|
|
||||||
String c = content.parse(null, params);
|
|
||||||
if (c == null) return this;
|
|
||||||
return insertLore(path, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem insertLore(@NotNull String path,
|
|
||||||
@NotNull ConfiguredMessageList<String> content, @NotNull Object... params) {
|
|
||||||
List<String> c = content.parse(null, params);
|
|
||||||
if (c == null || c.isEmpty()) return this;
|
|
||||||
return insertLore(path, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem amount(int amount) {
|
|
||||||
return handleItem((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 handleMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem addItemFlags(ItemFlag... flags) {
|
|
||||||
return handleMeta((meta, player) -> meta.addItemFlags(flags));
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem glow() {
|
|
||||||
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param owner 玩家名
|
|
||||||
* @return this
|
|
||||||
* @deprecated Use {@link #setSkullOwner(OfflinePlayer)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PreparedItem setSkullOwner(String owner) {
|
|
||||||
return handleItem((item, player) -> {
|
|
||||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
meta.setOwner(owner);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem setSkullOwner(UUID owner) {
|
|
||||||
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedItem setSkullOwner(OfflinePlayer owner) {
|
|
||||||
return handleItem((item, player) -> {
|
|
||||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
meta.setOwningPlayer(owner);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected Map<String, Object> buildPlaceholders() {
|
|
||||||
Map<String, Object> finalPlaceholders = new HashMap<>();
|
|
||||||
finalPlaceholders.putAll(ParamsUtils.buildParams(params, values));
|
|
||||||
finalPlaceholders.putAll(this.placeholders);
|
|
||||||
return finalPlaceholders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> parseLore(@Nullable Player player, @Nullable List<String> lore,
|
|
||||||
@NotNull Map<String, LoreContent> insertedLore,
|
|
||||||
@NotNull Map<String, Object> placeholders) {
|
|
||||||
List<String> parsedLore = new ArrayList<>();
|
|
||||||
if (lore == null || lore.isEmpty()) return parsedLore;
|
|
||||||
|
|
||||||
for (String line : lore) {
|
|
||||||
Matcher matcher = PreparedItem.LORE_INSERT_PATTERN.matcher(line);
|
|
||||||
if (!matcher.matches()) {
|
|
||||||
parsedLore.add(TextParser.parseText(player, line, placeholders));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = matcher.group(2);
|
|
||||||
LoreContent content = insertedLore.get(path);
|
|
||||||
if (content == null) continue;
|
|
||||||
|
|
||||||
String prefix = Optional.ofNullable(matcher.group(1))
|
|
||||||
.map(s -> TextParser.parseText(player, s, placeholders))
|
|
||||||
.orElse("");
|
|
||||||
int offset1 = Optional.ofNullable(matcher.group(3))
|
|
||||||
.map(Integer::parseInt).orElse(0);
|
|
||||||
Integer offset2 = Optional.ofNullable(matcher.group(4))
|
|
||||||
.map(Integer::parseInt).orElse(null);
|
|
||||||
|
|
||||||
List<String> inserted = parseLoreLine(
|
|
||||||
player, content, placeholders, prefix,
|
|
||||||
offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2
|
|
||||||
);
|
|
||||||
|
|
||||||
if (content.isOriginal()) {
|
|
||||||
parsedLore.addAll(inserted);
|
|
||||||
} else {
|
|
||||||
parsedLore.addAll(TextParser.parseList(player, inserted, placeholders));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parsedLore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent content,
|
|
||||||
@NotNull Map<String, Object> placeholders,
|
|
||||||
@NotNull String parsedPrefix, int upOffset, int downOffset) {
|
|
||||||
if (content.getContent().isEmpty()) return Collections.emptyList();
|
|
||||||
|
|
||||||
upOffset = Math.max(0, upOffset);
|
|
||||||
downOffset = Math.max(0, downOffset);
|
|
||||||
|
|
||||||
List<String> finalLore = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < upOffset; i++) finalLore.add(" ");
|
|
||||||
if (content.isOriginal()) {
|
|
||||||
content.getContent().stream().map(s -> parsedPrefix + s).forEach(finalLore::add);
|
|
||||||
} else {
|
|
||||||
content.getContent().stream().map(s -> parsedPrefix + TextParser.parseText(player, s, placeholders))
|
|
||||||
.forEach(finalLore::add);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < downOffset; i++) finalLore.add(" ");
|
|
||||||
|
|
||||||
return finalLore;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.notify.NotifyConfigBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ConfiguredNotify extends ConfiguredList<NotifyConfig> {
|
||||||
|
|
||||||
|
public static NotifyConfigBuilder create() {
|
||||||
|
return new NotifyConfigBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Set<NotifyType<?>> TYPES = new HashSet<>(Arrays.asList(DefaultNotifyTypes.values()));
|
||||||
|
|
||||||
|
public static NotifyType<?> getType(@NotNull String key) {
|
||||||
|
return TYPES.stream().filter(type -> type.key.equalsIgnoreCase(key)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
public ConfiguredNotify(@NotNull ValueManifest<List<NotifyConfig>> manifest, @NotNull String[] params) {
|
||||||
|
super(manifest, NotifyConfig.class, obj -> Objects.requireNonNull(NotifyConfig.deserialize(String.valueOf(obj))), NotifyConfig::serialize);
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull PreparedNotify prepare(@NotNull Object... values) {
|
||||||
|
return new PreparedNotify(getNotNull(), ParamsUtils.buildParams(getParams(), values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player, @NotNull Object... values) {
|
||||||
|
prepare(values).to(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Iterable<? extends Player> players, @NotNull Object... values) {
|
||||||
|
prepare(values).to(players);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAll(@NotNull String... values) {
|
||||||
|
prepare(values).toAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.SoundNotify;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.StringNotify;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.TitleNotify;
|
||||||
|
import com.cryptomorin.xseries.messages.ActionBar;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface DefaultNotifyTypes {
|
||||||
|
|
||||||
|
StringNotify MESSAGE = StringNotify.of("MESSAGE", Player::sendMessage, content -> Optional.ofNullable(content).orElse(" "));
|
||||||
|
StringNotify MSG = StringNotify.of("MSG", Player::sendMessage);
|
||||||
|
StringNotify ACTIONBAR = StringNotify.of("ACTIONBAR", ActionBar::sendActionBar);
|
||||||
|
TitleNotify TITLE = new TitleNotify("TITLE");
|
||||||
|
SoundNotify SOUND = new SoundNotify("SOUND");
|
||||||
|
|
||||||
|
static NotifyType<?>[] values() {
|
||||||
|
return new NotifyType<?>[]{MESSAGE, MSG, ACTIONBAR, TITLE, SOUND};
|
||||||
|
}
|
||||||
|
|
||||||
|
static NotifyType<?> valueOf(String name) {
|
||||||
|
return Arrays.stream(values()).filter(type -> type.key.equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class NotifyCache<T extends NotifyType<M>, M> {
|
||||||
|
|
||||||
|
// Notify config format: [TYPE(@PARAM)] CONTENTS...
|
||||||
|
public static final @NotNull Pattern CONFIG_FORMAT = Pattern.compile("\\[(?<type>[^@\\]]+)(@(?<param>[^]]+))?] (?<content>.*)");
|
||||||
|
|
||||||
|
public static @Nullable NotifyCache<?, ?> deserialize(@NotNull String config) {
|
||||||
|
// parse config with config_format
|
||||||
|
Matcher matcher = CONFIG_FORMAT.matcher(config.trim());
|
||||||
|
if (!matcher.matches()) return of("MESSAGE", null, config);
|
||||||
|
return of(matcher.group("type"), matcher.group("param"), matcher.group("content"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable NotifyCache<?, ?> of(@NotNull String key, @Nullable String param, @Nullable String content) {
|
||||||
|
NotifyType<?> type = ConfiguredNotify.getType(key);
|
||||||
|
if (type == null) return null;
|
||||||
|
return NotifyCache.of(type, param, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable String param, @Nullable String content) {
|
||||||
|
return new NotifyCache<>(type, type.parseMeta(param, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable M meta) {
|
||||||
|
return new NotifyCache<>(type, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull T type;
|
||||||
|
protected final @Nullable M meta;
|
||||||
|
|
||||||
|
public NotifyCache(@NotNull T type, @Nullable M meta) {
|
||||||
|
this.type = type;
|
||||||
|
this.meta = meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull T getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M getMeta() {
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
type.execute(player, meta, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serialize() {
|
||||||
|
return type.serializeConfig(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class NotifyType<M> {
|
||||||
|
|
||||||
|
protected final @NotNull String key;
|
||||||
|
protected final @NotNull Class<M> metaClass;
|
||||||
|
|
||||||
|
protected NotifyType(@NotNull String key, @NotNull Class<M> metaClass) {
|
||||||
|
this.key = key;
|
||||||
|
this.metaClass = metaClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Class<M> getMetaClass() {
|
||||||
|
return metaClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse metadata from string.
|
||||||
|
* <br> e.g. "[TYPE-KEY@PARAM] CONTENTS..."
|
||||||
|
*
|
||||||
|
* @param param The param of the notify config.
|
||||||
|
* @param content The content of the notify config.
|
||||||
|
* @return The parsed metadata.
|
||||||
|
*/
|
||||||
|
public abstract @Nullable M parseMeta(@Nullable String param, @Nullable String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the metadata to singleton string to storage on configs.
|
||||||
|
*
|
||||||
|
* @param meta The parsed metadata.
|
||||||
|
* @return The serialized string.
|
||||||
|
*/
|
||||||
|
public abstract @NotNull String serializeConfig(@Nullable M meta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the notify content to specific player.
|
||||||
|
*
|
||||||
|
* @param player The player who receive the notification.
|
||||||
|
* @param meta The parsed metadata.
|
||||||
|
*/
|
||||||
|
public abstract void execute(@NotNull Player player, @Nullable M meta, @NotNull Map<String, Object> placeholders);
|
||||||
|
|
||||||
|
@Contract("_, _, null -> null; _, _, !null -> !null")
|
||||||
|
protected String setPlaceholders(@NotNull Player player, @Nullable String content,
|
||||||
|
@NotNull Map<String, Object> placeholders) {
|
||||||
|
return TextParser.parseText(player, content, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PreparedNotify {
|
||||||
|
|
||||||
|
protected final @NotNull List<NotifyConfig> notifications;
|
||||||
|
protected final @NotNull Map<String, Object> placeholders;
|
||||||
|
|
||||||
|
protected PreparedNotify(@NotNull List<NotifyConfig> notifications, @NotNull Map<String, Object> placeholders) {
|
||||||
|
this.notifications = notifications;
|
||||||
|
this.placeholders = placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向某位接收者发送消息
|
||||||
|
*
|
||||||
|
* @param receiver 消息的接收者
|
||||||
|
*/
|
||||||
|
public void to(@NotNull Player receiver) {
|
||||||
|
notifications.forEach(config -> config.execute(receiver, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向某位接收者发送消息
|
||||||
|
*
|
||||||
|
* @param receivers 消息的接收者们
|
||||||
|
*/
|
||||||
|
public void to(@NotNull Iterable<? extends Player> receivers) {
|
||||||
|
receivers.forEach(this::to);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toAll() {
|
||||||
|
to(Bukkit.getOnlinePlayers());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SoundNotify extends NotifyType<SoundConfig> {
|
||||||
|
|
||||||
|
|
||||||
|
public SoundNotify(@NotNull String key) {
|
||||||
|
super(key, SoundConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable SoundConfig parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
|
||||||
|
String[] args = param == null ? new String[0] : param.split(",");
|
||||||
|
try {
|
||||||
|
return new SoundConfig(content.trim(),
|
||||||
|
(args.length >= 1) ? Float.parseFloat(args[0]) : 1,
|
||||||
|
(args.length >= 2) ? Float.parseFloat(args[1]) : 1
|
||||||
|
);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable SoundConfig meta) {
|
||||||
|
if (meta == null) return "[" + key + "] ";
|
||||||
|
|
||||||
|
if (meta.getVolume() == 1 && meta.getPitch() == 1) {
|
||||||
|
return "[" + key + "] " + meta.getTypeName();
|
||||||
|
} else {
|
||||||
|
return "[" + key + "@" + +meta.getVolume() + "," + meta.getPitch() + "] " + meta.getTypeName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable SoundConfig meta, @NotNull Map<String, Object> placeholders) {
|
||||||
|
System.out.println("SoundNotify.execute");
|
||||||
|
if (meta != null) {
|
||||||
|
System.out.println("SoundNotify.play");
|
||||||
|
meta.playTo(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
public abstract class StringNotify extends NotifyType<String> {
|
||||||
|
|
||||||
|
public static StringNotify of(String key, BiConsumer<Player, String> consumer) {
|
||||||
|
return of(key, consumer, (content) -> "[" + key + "] " + (content == null ? " " : content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringNotify of(String key,
|
||||||
|
BiConsumer<Player, String> consumer,
|
||||||
|
UnaryOperator<String> serializer) {
|
||||||
|
return new StringNotify(key) {
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable String meta) {
|
||||||
|
return serializer.apply(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(@NotNull Player player, @NotNull String parsedContent) {
|
||||||
|
consumer.accept(player, parsedContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected StringNotify(String key) {
|
||||||
|
super(key, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void send(@NotNull Player player, @NotNull String parsedContent);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable String content, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (content == null) return;
|
||||||
|
send(player, setPlaceholders(player, content, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
|
||||||
|
import com.cryptomorin.xseries.messages.Titles;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class TitleNotify extends NotifyType<TitleConfig> {
|
||||||
|
|
||||||
|
//Content format line1{N}line2
|
||||||
|
public static final Pattern CONTENT_FORMAT = Pattern.compile("(?<line1>.+?)(?:\\{n}(?<line2>.+))?");
|
||||||
|
//Param format fadeIn,stay,fadeOut
|
||||||
|
public static final Pattern PARAM_FORMAT = Pattern.compile("(?<fadeIn>\\d+),(?<stay>\\d+),(?<fadeOut>\\d+)");
|
||||||
|
|
||||||
|
public TitleNotify(String key) {
|
||||||
|
super(key, TitleConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TitleConfig parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
|
||||||
|
Matcher contentMatcher = CONTENT_FORMAT.matcher(content);
|
||||||
|
if (!contentMatcher.matches()) return null;
|
||||||
|
|
||||||
|
if (param == null) {
|
||||||
|
return TitleConfig.of(contentMatcher.group("line1"), contentMatcher.group("line2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher paramMatcher = PARAM_FORMAT.matcher(param);
|
||||||
|
if (!paramMatcher.matches()) {
|
||||||
|
return TitleConfig.of(contentMatcher.group("line1"), contentMatcher.group("line2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TitleConfig.of(
|
||||||
|
contentMatcher.group("line1"), contentMatcher.group("line2"),
|
||||||
|
Integer.parseInt(paramMatcher.group("fadeIn")),
|
||||||
|
Integer.parseInt(paramMatcher.group("stay")),
|
||||||
|
Integer.parseInt(paramMatcher.group("fadeOut"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable TitleConfig meta) {
|
||||||
|
if (meta == null || (meta.getLine1() == null && meta.getLine2() == null)) return "[" + key + "] ";
|
||||||
|
|
||||||
|
String line1 = meta.getLine1() == null ? "" : meta.getLine1().getMessage();
|
||||||
|
String line2 = meta.getLine2() == null ? "" : meta.getLine2().getMessage();
|
||||||
|
|
||||||
|
if (meta.isStandardTime()) {
|
||||||
|
return "[" + key + "] " + line1 + "{n}" + line1;
|
||||||
|
} else
|
||||||
|
return "[" + key + "@" + meta.getFadeIn() + "," + meta.getStay() + "," + meta.getFadeOut() + "] " + line1 + "{n}" + line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable TitleConfig meta, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (meta != null) meta.send(player, placeholders, Titles::sendTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ public class LoreInsertTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
List<String> replace = Arrays.asList("> 插入的点击行1", "> 插入的点击行2");
|
List<String> replace = Arrays.asList("> 插入的点击行1", "> 插入的点击行2");
|
||||||
Map<String, LoreContent> inserted = new HashMap<>();
|
Map<String, LoreContent<?>> inserted = new HashMap<>();
|
||||||
inserted.put("click-lore", LoreContent.of(replace));
|
inserted.put("click-lore", LoreContent.of(replace));
|
||||||
PreparedItem.parseLore(null, original, inserted, new HashMap<>()).forEach(System.out::println);
|
PreparedItem.parseLore(null, original, inserted, new HashMap<>()).forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>2.8.6</version>
|
<version>2.9.2</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
+5
-4
@@ -1,5 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee;
|
package cc.carm.lib.mineconfiguration.bungee;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.Configuration;
|
||||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
@@ -103,16 +104,16 @@ public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MineConfiguration(@NotNull Plugin plugin,
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
@NotNull ConfigurationRoot configRoot,
|
@NotNull Configuration configRoot,
|
||||||
@NotNull ConfigurationRoot messageRoot) {
|
@NotNull Configuration messageRoot) {
|
||||||
this(plugin);
|
this(plugin);
|
||||||
initializeConfig(configRoot);
|
initializeConfig(configRoot);
|
||||||
initializeMessage(messageRoot);
|
initializeMessage(messageRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MineConfiguration(@NotNull Plugin plugin,
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
this(plugin);
|
this(plugin);
|
||||||
initializeConfig(configRoot);
|
initializeConfig(configRoot);
|
||||||
initializeMessage(messageRoot);
|
initializeMessage(messageRoot);
|
||||||
|
|||||||
@@ -10,14 +10,14 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
<deps.easyconfifuration.version>3.8.0</deps.easyconfifuration.version>
|
<deps.easyconfifuration.version>3.9.1</deps.easyconfifuration.version>
|
||||||
<deps.easyplugin.version>1.5.8</deps.easyplugin.version>
|
<deps.easyplugin.version>1.5.11</deps.easyplugin.version>
|
||||||
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
|
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>2.8.6</version>
|
<version>2.9.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>24.0.1</version>
|
<version>24.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.2.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -161,7 +161,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.12.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${project.jdk.version}</source>
|
<source>${project.jdk.version}</source>
|
||||||
<target>${project.jdk.version}</target>
|
<target>${project.jdk.version}</target>
|
||||||
@@ -196,7 +196,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
|
|||||||
Reference in New Issue
Block a user