mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d55ddbce9 | |||
| c73032266d | |||
| a6b6d46be6 | |||
| 47d7b17082 | |||
| 0663f3d117 | |||
| 1947ba1899 | |||
| 2e4de9880f | |||
| 398bc773d6 | |||
| 1396c6bd6e | |||
| 2959c00795 | |||
| 09537975e4 | |||
| 02625b5c0c | |||
| bb9e24dd96 | |||
| 5bdc5908ef | |||
| dde304625e | |||
| 24ef0b6dcd | |||
| a1d6cf1258 | |||
| 0f7fc39f87 | |||
| 92ecb55a95 | |||
| bfd1624e85 | |||
| 01d3c245a9 | |||
| 8721c6085f | |||
| eca4d47b8f | |||
| 3750ac7d58 | |||
| d3bdc4ad60 | |||
| 6bb6fb1b95 | |||
| dd2499512c | |||
| 3aa0542f01 | |||
| 4d9d5f5d84 | |||
| 2b31ee1318 |
@@ -22,7 +22,7 @@ jobs:
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
# cache: maven # Say 4uck u to github cache services.
|
||||
server-id: github
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
# cache: maven # Say 4uck u to github cache services.
|
||||
server-id: ossrh
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_PASSWORD
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.8.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
@@ -39,7 +39,7 @@
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.16-R0.4</version>
|
||||
<version>1.20-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -38,6 +38,16 @@ public interface BaseMessage<R, M> {
|
||||
@ApiStatus.OverrideOnly
|
||||
void apply(@NotNull R receiver, @NotNull M message);
|
||||
|
||||
/**
|
||||
* 填入变量值,返回一个准备好待发送的消息。
|
||||
*
|
||||
* @param values 变量值
|
||||
* @return 准备好待发送的消息
|
||||
*/
|
||||
default @NotNull PreparedMessage<R, M> prepare(@NotNull Object... values) {
|
||||
return new PreparedMessage<>(this, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
|
||||
@@ -7,6 +7,7 @@ import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -71,4 +72,28 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
return textBuilder.apply(value);
|
||||
}
|
||||
|
||||
public abstract class PreparedMessage<P, N> {
|
||||
|
||||
protected final @NotNull Object[] values;
|
||||
|
||||
protected PreparedMessage(@NotNull Object[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Object[] getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public abstract void to(P receiver);
|
||||
|
||||
public void to(Collection<P> receivers) {
|
||||
receivers.forEach(this::to);
|
||||
}
|
||||
|
||||
public N get(P receiver) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PreparedMessage<R, M> {
|
||||
|
||||
protected final @NotNull BaseMessage<R, M> message;
|
||||
protected final @NotNull Object[] values;
|
||||
|
||||
protected PreparedMessage(@NotNull BaseMessage<R, M> message, @NotNull Object[] values) {
|
||||
this.message = message;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
public @Nullable M parse(@Nullable R receiver) {
|
||||
return message.parse(receiver, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
*/
|
||||
public void to(@Nullable R receiver) {
|
||||
message.send(receiver, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receivers 消息的接收者们
|
||||
*/
|
||||
public void to(@NotNull Iterable<R> receivers) {
|
||||
receivers.forEach(this::to);
|
||||
}
|
||||
|
||||
public void toAll() {
|
||||
to(message.getAllReceivers());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.8.7</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -40,7 +40,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>XSeries</artifactId>
|
||||
<version>9.3.1</version>
|
||||
<version>9.6.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.3</version>
|
||||
<version>2.11.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
+5
-8
@@ -2,32 +2,29 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.title;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import com.cryptomorin.xseries.messages.Titles;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
|
||||
|
||||
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
|
||||
|
||||
protected @NotNull String[] params = new String[0];
|
||||
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10;
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60;
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10;
|
||||
|
||||
protected @NotNull TitleSendConsumer sendConsumer;
|
||||
protected @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
public TitleConfigBuilder() {
|
||||
this.sendConsumer = TitleConfigBuilder.DEFAULT_TITLE_CONSUMER;
|
||||
this.sendConsumer = ConfiguredTitle.DEFAULT_TITLE_CONSUMER;
|
||||
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
}
|
||||
|
||||
@@ -36,7 +33,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
return defaults(TitleConfig.of(line1, line2));
|
||||
}
|
||||
|
||||
public @NotNull TitleConfigBuilder whenSend(@NotNull TitleSendConsumer consumer) {
|
||||
public @NotNull TitleConfigBuilder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
|
||||
this.sendConsumer = consumer;
|
||||
return this;
|
||||
}
|
||||
@@ -65,7 +62,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder formatParam(Function<String, String> paramFormatter) {
|
||||
public TitleConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return this;
|
||||
}
|
||||
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemConfig {
|
||||
|
||||
protected @NotNull Material type;
|
||||
protected short data;
|
||||
protected @Nullable String name;
|
||||
protected @NotNull List<String> lore;
|
||||
|
||||
protected @NotNull Map<Enchantment, Integer> enchants;
|
||||
protected @NotNull Set<ItemFlag> flags;
|
||||
|
||||
protected int customModelData = 0;
|
||||
|
||||
public ItemConfig(@NotNull Material type, @Nullable String name) {
|
||||
this(type, name, Collections.emptyList());
|
||||
}
|
||||
|
||||
public ItemConfig(@NotNull Material type, @Nullable String name, @NotNull List<String> lore) {
|
||||
this(type, (short) 0, name, lore);
|
||||
}
|
||||
|
||||
public ItemConfig(@NotNull Material type, short damage,
|
||||
@Nullable String name, @NotNull List<String> lore) {
|
||||
this(type, damage, name, lore, Collections.emptyMap(), Collections.emptySet());
|
||||
}
|
||||
|
||||
public ItemConfig(@NotNull Material type, short damage,
|
||||
@Nullable String name, @NotNull List<String> lore,
|
||||
@NotNull Map<Enchantment, Integer> enchants,
|
||||
@NotNull Set<ItemFlag> flags) {
|
||||
this.type = type;
|
||||
this.data = damage;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.enchants = enchants;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public @NotNull Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public short getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @Nullable String getName(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
return Optional.ofNullable(getName())
|
||||
.map(name -> TextParser.parseText(player, name, placeholders))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getLore() {
|
||||
return lore;
|
||||
}
|
||||
|
||||
public @Nullable List<String> getLore(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
if (getLore().isEmpty()) return null;
|
||||
else return TextParser.parseList(player, getLore(), placeholders);
|
||||
}
|
||||
|
||||
public final @NotNull ItemStack getItemStack() {
|
||||
return getItemStack(1);
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(int amount) {
|
||||
return getItemStack(null, amount, new HashMap<>());
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
||||
return getItemStack(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
return getItemStack(player, 1, placeholders);
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
||||
ItemStack item = new ItemStack(type, amount, data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
|
||||
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
|
||||
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||
flags.forEach(meta::addItemFlags);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("type", type.name());
|
||||
if (this.data != 0) map.put("data", data);
|
||||
if (name != null) map.put("name", name);
|
||||
if (!lore.isEmpty()) map.put("lore", lore);
|
||||
|
||||
Map<String, Integer> enchantments = new LinkedHashMap<>();
|
||||
enchants.forEach((enchant, level) -> {
|
||||
if (level > 0) enchantments.put(enchant.getName(), level);
|
||||
});
|
||||
|
||||
if (!enchantments.isEmpty()) {
|
||||
map.put("enchants", enchantments);
|
||||
}
|
||||
|
||||
if (!flags.isEmpty()) {
|
||||
map.put("flags", flags.stream().map(ItemFlag::name).collect(Collectors.toList()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
|
||||
return deserialize(CraftSectionWrapper.of(section));
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
|
||||
String typeName = section.getString("type");
|
||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||
|
||||
Material type = Material.matchMaterial(typeName);
|
||||
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
||||
|
||||
short data = section.getShort("data", (short) 0);
|
||||
String name = section.getString("name");
|
||||
List<String> lore = section.getStringList("lore");
|
||||
|
||||
Map<Enchantment, Integer> enchantments = readEnchantments(section.getConfigurationSection("enchants"));
|
||||
Set<ItemFlag> flags = readFlags(section.getStringList("flags"));
|
||||
|
||||
return new ItemConfig(type, data, name, lore, enchantments, flags);
|
||||
}
|
||||
|
||||
private static ItemFlag parseFlag(String flagName) {
|
||||
return Arrays.stream(ItemFlag.values()).filter(flag -> flag.name().equalsIgnoreCase(flagName)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private static Set<ItemFlag> readFlags(List<String> flagConfig) {
|
||||
Set<ItemFlag> flags = new LinkedHashSet<>();
|
||||
for (String flagName : flagConfig) {
|
||||
ItemFlag flag = parseFlag(flagName);
|
||||
if (flag != null) flags.add(flag);
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper<?> section) {
|
||||
Map<Enchantment, Integer> enchantments = new LinkedHashMap<>();
|
||||
if (section == null) return enchantments;
|
||||
section.getKeys(false).forEach(key -> {
|
||||
Enchantment enchantment = Enchantment.getByName(key);
|
||||
int level = section.getInt(key, 0);
|
||||
if (enchantment != null && level > 0) {
|
||||
enchantments.put(enchantment, level);
|
||||
}
|
||||
});
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
}
|
||||
+57
-7
@@ -1,8 +1,8 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,20 +25,58 @@ public class TitleConfig {
|
||||
return new TitleConfig(line1, line2);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
return of(
|
||||
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
|
||||
Optional.ofNullable(line2).map(TextConfig::of).orElse(null),
|
||||
fadeIn, stay, fadeOut
|
||||
);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
return new TitleConfig(line1, line2, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
protected @Nullable TextConfig line1;
|
||||
protected @Nullable TextConfig line2;
|
||||
|
||||
protected final int fadeIn;
|
||||
protected final int stay;
|
||||
protected final int fadeOut;
|
||||
|
||||
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||
this(line1, line2, -1, -1, -1);
|
||||
}
|
||||
|
||||
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2, int fadeIn, int stay, int fadeOut) {
|
||||
this.line1 = line1;
|
||||
this.line2 = line2;
|
||||
this.fadeIn = fadeIn;
|
||||
this.stay = stay;
|
||||
this.fadeOut = fadeOut;
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int fadeOut,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@Nullable TitleSendConsumer sendConsumer) {
|
||||
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||
send(
|
||||
player,
|
||||
this.fadeIn < 0 ? 10 : this.fadeIn,
|
||||
this.stay < 0 ? 60 : this.stay,
|
||||
this.fadeOut < 0 ? 10 : this.fadeOut,
|
||||
placeholders,
|
||||
sendConsumer
|
||||
);
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||
if (this.line1 == null && this.line2 == null) return;
|
||||
if (sendConsumer == null) return;
|
||||
sendConsumer.send(
|
||||
@@ -58,11 +96,23 @@ public class TitleConfig {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
if (this.line1 != null) map.put("line1", this.line1.getMessage());
|
||||
if (this.line2 != null) map.put("line2", this.line2.getMessage());
|
||||
if (this.fadeIn > 0) map.put("fadeIn", this.fadeIn);
|
||||
if (this.stay > 0) map.put("stay", this.stay);
|
||||
if (this.fadeOut > 0) map.put("fadeOut", this.fadeOut);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
|
||||
return of(section.getString("line1"), section.getString("line2"));
|
||||
public static @Nullable TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
|
||||
String line1 = section.getString("line1");
|
||||
String line2 = section.getString("line2");
|
||||
if (line1 == null && line2 == null) return null;
|
||||
|
||||
return of(
|
||||
line1, line2,
|
||||
section.getInt("fadeIn", -1),
|
||||
section.getInt("stay", -1),
|
||||
section.getInt("fadeOut", -1)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.function;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TitleSendConsumer {
|
||||
|
||||
/**
|
||||
* 向目标玩家发送标题文字
|
||||
*
|
||||
* @param player 目标玩家
|
||||
* @param fadeIn 淡入时间 (ticks)
|
||||
* @param stay 保留时间 (ticks)
|
||||
* @param fadeOut 淡出时间 (ticks)
|
||||
* @param line1 第一行文字
|
||||
* @param line2 第二行文字
|
||||
*/
|
||||
void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull String line1, @NotNull String line2);
|
||||
|
||||
}
|
||||
+28
-4
@@ -7,8 +7,8 @@ import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import com.cryptomorin.xseries.messages.Titles;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,6 +22,8 @@ import java.util.function.Predicate;
|
||||
|
||||
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
|
||||
public static final @NotNull ConfiguredTitle.TitleConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
|
||||
|
||||
public static TitleConfigBuilder create() {
|
||||
return CraftConfigValue.builder().createTitle();
|
||||
}
|
||||
@@ -35,7 +37,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build();
|
||||
}
|
||||
|
||||
protected final @NotNull TitleSendConsumer sendConsumer;
|
||||
protected final @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
|
||||
protected final @NotNull String[] params;
|
||||
|
||||
protected final int fadeIn;
|
||||
@@ -43,7 +45,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
protected final int fadeOut;
|
||||
|
||||
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
|
||||
@NotNull TitleSendConsumer sendConsumer,
|
||||
@NotNull ConfiguredTitle.TitleConsumer sendConsumer,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
|
||||
this.sendConsumer = sendConsumer;
|
||||
@@ -68,7 +70,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
return fadeOut;
|
||||
}
|
||||
|
||||
public @NotNull TitleSendConsumer getSendConsumer() {
|
||||
public @NotNull ConfiguredTitle.TitleConsumer getSendConsumer() {
|
||||
return sendConsumer;
|
||||
}
|
||||
|
||||
@@ -116,4 +118,26 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
|
||||
return (s, d) -> TitleConfig.deserialize(s);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TitleConsumer {
|
||||
|
||||
/**
|
||||
* 向目标玩家发送标题文字
|
||||
*
|
||||
* @param player 目标玩家
|
||||
* @param fadeIn 淡入时间 (ticks)
|
||||
* @param stay 保留时间 (ticks)
|
||||
* @param fadeOut 淡出时间 (ticks)
|
||||
* @param line1 第一行文字
|
||||
* @param line2 第二行文字
|
||||
*/
|
||||
void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull String line1, @NotNull String line2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+42
-45
@@ -1,10 +1,8 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import com.cryptomorin.xseries.XItemStack;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -13,14 +11,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||
|
||||
|
||||
public static ItemConfigBuilder create() {
|
||||
return new ItemConfigBuilder();
|
||||
}
|
||||
@@ -40,6 +36,45 @@ public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<@Nullable ItemStack> getOptional() {
|
||||
return Optional.ofNullable(super.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack get() {
|
||||
return getOptional().map(ItemStack::clone).orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||
return getOptional().map(item -> {
|
||||
modifier.accept(item);
|
||||
return item;
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
public @NotNull PreparedItem prepare(@NotNull Object... values) {
|
||||
return PreparedItem.of(player -> get()).params(params).values(values);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player) {
|
||||
return get(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||
return prepare(values).get(player);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||
return prepare().params(params).values(values).get(player);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player,
|
||||
@NotNull Map<String, Object> placeholders) {
|
||||
return prepare().placeholders(placeholders).get(player);
|
||||
}
|
||||
|
||||
|
||||
public void modifyItem(Consumer<ItemStack> modifier) {
|
||||
ItemStack item = get();
|
||||
if (item == null) return;
|
||||
@@ -68,42 +103,4 @@ public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||
else setLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player) {
|
||||
return get(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||
return get(player, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||
return get(player, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
return get((item) -> {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore != null && !lore.isEmpty()) {
|
||||
meta.setLore(TextParser.parseList(player, lore, placeholders));
|
||||
}
|
||||
|
||||
String name = meta.getDisplayName();
|
||||
if (!name.isEmpty()) {
|
||||
meta.setDisplayName(TextParser.parseText(player, name, placeholders));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||
return getOptional().map(item -> {
|
||||
modifier.accept(item);
|
||||
return item;
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
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.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> itemModifier;
|
||||
protected @NotNull BiConsumer<ItemMeta, Player> metaModifier;
|
||||
|
||||
protected ItemModifier(@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) -> {
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
metaModifier.accept(meta, player);
|
||||
item.setItemMeta(meta);
|
||||
itemModifier.accept(item, player);
|
||||
}
|
||||
|
||||
public S handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
||||
this.metaModifier = this.metaModifier.andThen(modifier);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public S handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
||||
this.itemModifier = this.itemModifier.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) {
|
||||
String c = content.parse(null, params);
|
||||
if (c == null) return getThis();
|
||||
return insertLore(path, c);
|
||||
}
|
||||
|
||||
public S insertLore(@NotNull String path,
|
||||
@NotNull ConfiguredMessageList<String> content, @NotNull Object... params) {
|
||||
List<String> c = content.parse(null, params);
|
||||
if (c == null || c.isEmpty()) return getThis();
|
||||
return insertLore(path, c);
|
||||
}
|
||||
|
||||
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 handleItem((item, player) -> {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
});
|
||||
}
|
||||
|
||||
public S setSkullOwner(UUID owner) {
|
||||
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
|
||||
}
|
||||
|
||||
public S 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 = 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;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoreContent {
|
||||
|
||||
public static LoreContent of(@NotNull List<String> content) {
|
||||
return of(content, false);
|
||||
}
|
||||
|
||||
public static LoreContent of(@NotNull List<String> content, boolean original) {
|
||||
return new LoreContent(content, original);
|
||||
}
|
||||
|
||||
protected final @NotNull List<String> content;
|
||||
protected final boolean original;
|
||||
|
||||
public LoreContent(@NotNull List<String> content, boolean original) {
|
||||
this.content = content;
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
|
||||
public @NotNull List<String> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public boolean isOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PreparedItem extends ItemModifier<PreparedItem, ItemStack> {
|
||||
|
||||
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||
return new PreparedItem(itemProvider);
|
||||
}
|
||||
|
||||
public static PreparedItem of(@Nullable ItemStack item) {
|
||||
return of(player -> item);
|
||||
}
|
||||
|
||||
public PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||
super(itemProvider);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Player player) {
|
||||
@Nullable ItemStack item = itemProvider.apply(player);
|
||||
if (item == null) return null;
|
||||
|
||||
applyTo(item, player);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PreparedItem getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.LoreContent;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class LoreInsertTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
List<String> original = Arrays.asList(
|
||||
"测试lore的第一行",
|
||||
"测试lore的第二行",
|
||||
"#click-lore#{1,2}",
|
||||
"测试lore的倒数第二行",
|
||||
"{--> }#click-lore#{2}",
|
||||
"测试lore的倒数第一行"
|
||||
);
|
||||
|
||||
List<String> replace = Arrays.asList("> 插入的点击行1", "> 插入的点击行2");
|
||||
Map<String, LoreContent> inserted = new HashMap<>();
|
||||
inserted.put("click-lore", LoreContent.of(replace));
|
||||
PreparedItem.parseLore(null, original, inserted, new HashMap<>()).forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
System.out.println(parse("{LOVE}#click-lore#{1,0}"));
|
||||
System.out.println(parse("#click-lore#{1,2}"));
|
||||
System.out.println(parse("#click-lore#{1}"));
|
||||
System.out.println(parse("#click-lore#{我}"));
|
||||
}
|
||||
|
||||
public static String parse(String line) {
|
||||
Matcher matcher = PreparedItem.LORE_INSERT_PATTERN.matcher(line);
|
||||
if (!matcher.matches()) {
|
||||
return "Failed -> [" + line + "]";
|
||||
} else {
|
||||
String prefix = matcher.group(1);
|
||||
String path = matcher.group(2);
|
||||
|
||||
String offset1 = matcher.group(3);
|
||||
String offset2 = matcher.group(4);
|
||||
return "Prefix -> [" + prefix + "] Path -> [" + path + "] Offset-> [" + offset1 + "/" + offset2 + "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.8.7</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
|
||||
<deps.easyconfifuration.version>3.6.0</deps.easyconfifuration.version>
|
||||
<deps.easyplugin.version>1.5.4</deps.easyplugin.version>
|
||||
<deps.easyconfifuration.version>3.8.0</deps.easyconfifuration.version>
|
||||
<deps.easyplugin.version>1.5.8</deps.easyplugin.version>
|
||||
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.8.7</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>common</module>
|
||||
@@ -122,7 +122,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.2</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -150,7 +150,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
@@ -196,7 +196,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
@@ -225,7 +225,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
Reference in New Issue
Block a user