mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2024-09-19 20:05:49 +00:00
[1.2.2] 令物品配置原生支持PlaceholderAPI
This commit is contained in:
parent
29526223e4
commit
cf80291e51
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -20,14 +20,12 @@ public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, Mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull
|
public @NotNull <M> CraftMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
<M> CraftMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
|
||||||
return new CraftMessageValueBuilder<>(parser);
|
return new CraftMessageValueBuilder<>(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull
|
public @NotNull <M> CraftMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
<M> CraftMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
|
||||||
return new CraftMessageListBuilder<>(parser);
|
return new CraftMessageListBuilder<>(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +39,7 @@ public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, Mes
|
|||||||
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage));
|
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static @NotNull
|
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
||||||
BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
|
||||||
return (receiver, message) -> {
|
return (receiver, message) -> {
|
||||||
if (receiver instanceof Player && hasPlaceholderAPI()) {
|
if (receiver instanceof Player && hasPlaceholderAPI()) {
|
||||||
message = PAPIHelper.parseMessages((Player) receiver, message);
|
message = PAPIHelper.parseMessages((Player) receiver, message);
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
package cc.carm.lib.configuration.craft.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.common.utils.ColorParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.craft.utils.PAPIHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -49,16 +53,23 @@ public class ItemConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack(int amount) {
|
public @NotNull ItemStack getItemStack(int amount) {
|
||||||
|
return getItemStack(null, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
||||||
|
return getItemStack(player, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount) {
|
||||||
ItemStack item = new ItemStack(type, amount, data);
|
ItemStack item = new ItemStack(type, amount, data);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta == null) return item;
|
if (meta == null) return item;
|
||||||
if (getName() != null) meta.setDisplayName(getName());
|
if (getName() != null) meta.setDisplayName(parseName(player, getName()));
|
||||||
if (!getLore().isEmpty()) meta.setLore(getLore());
|
if (!getLore().isEmpty()) meta.setLore(parseLore(player, getLore()));
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public @NotNull Map<String, Object> serialize() {
|
public @NotNull Map<String, Object> serialize() {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("type", type.name());
|
map.put("type", type.name());
|
||||||
@ -89,4 +100,20 @@ public class ItemConfig {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static @NotNull String parseName(@Nullable Player player, String message) {
|
||||||
|
if (player != null && hasPlaceholderAPI()) message = PAPIHelper.parseMessages(player, message);
|
||||||
|
return ColorParser.parse(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static @NotNull List<String> parseLore(@Nullable Player player, List<String> messages) {
|
||||||
|
if (player != null && hasPlaceholderAPI()) messages = PAPIHelper.parseMessages(player, messages);
|
||||||
|
return ColorParser.parse(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlaceholderAPI() {
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -22,7 +22,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>MineConfiguration</name>
|
<name>MineConfiguration</name>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.1-SNAPSHOT</version>
|
<version>1.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
Loading…
Reference in New Issue
Block a user