new-1.1
This commit is contained in:
parent
db6c29f103
commit
ebd5431294
1
pom.xml
1
pom.xml
|
@ -115,7 +115,6 @@
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-compress</artifactId>
|
<artifactId>commons-compress</artifactId>
|
||||||
<version>1.27.1</version>
|
<version>1.27.1</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
|
|
@ -18,9 +18,7 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger(ElementOriginLib.class);
|
private static Logger logger = Logger.getLogger(ElementOriginLib.class);
|
||||||
|
|
||||||
private static RedisIO redisIO;
|
private RedisIO redisIO;
|
||||||
|
|
||||||
private static CommandManager commandManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -31,11 +29,9 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
new GuiHandlerListener(this);
|
new GuiHandlerListener(this);
|
||||||
new PlayerChatInputListener(this);
|
new PlayerChatInputListener(this);
|
||||||
|
|
||||||
commandManager = new CommandManager(this);
|
CommandManager.INSTANCE.registerPluginCommand("elementoriginlib");
|
||||||
commandManager.registerPluginCommand("elementoriginlib");
|
|
||||||
|
|
||||||
Lang.registerLangFile(this);
|
reload();
|
||||||
Lang.reload();
|
|
||||||
|
|
||||||
redisIO = new RedisIO();
|
redisIO = new RedisIO();
|
||||||
redisIO.init(this);
|
redisIO.init(this);
|
||||||
|
@ -49,11 +45,12 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
LibraryManager libraryManager = new BukkitLibraryManager(this);
|
LibraryManager libraryManager = new BukkitLibraryManager(this);
|
||||||
libraryManager.addMavenCentral();
|
libraryManager.addMavenCentral();
|
||||||
libraryManager.setLogLevel(LogLevel.WARN);
|
libraryManager.setLogLevel(LogLevel.WARN);
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("org{}apache{}commons").artifactId("commons-compress").version("1.27.1").build());
|
libraryManager.loadLibrary(Library.builder().groupId("org{}apache{}commons").artifactId("commons-compress").version("1.27.1").build());
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("com{}github{}luben").artifactId("zstd-jni").version("1.5.6-9").build());
|
libraryManager.loadLibrary(Library.builder().groupId("com{}github{}luben").artifactId("zstd-jni").version("1.5.6-9").build());
|
||||||
|
libraryManager.loadLibrary(Library.builder().groupId("com{}fasterxml{}jackson{}core").artifactId("jackson-databind").version("2.18.2").build());
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("com{}zaxxer").artifactId("HikariCP").version("6.2.1").build());
|
// libraryManager.loadLibrary(Library.builder().groupId("com{}zaxxer").artifactId("HikariCP").version("6.2.1").build());
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("org{}xerial").artifactId("sqlite-jdbc").version("3.46.0.0").build());
|
// libraryManager.loadLibrary(Library.builder().groupId("org{}xerial").artifactId("sqlite-jdbc").version("3.46.0.0").build());
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("redis{}clients").id("jedis").artifactId("jedis").version("5.2.0").build());
|
libraryManager.loadLibrary(Library.builder().groupId("redis{}clients").id("jedis").artifactId("jedis").version("5.2.0").build());
|
||||||
logger.info("Successfully loaded libraries.");
|
logger.info("Successfully loaded libraries.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +58,12 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RedisIO getRedisIO() {
|
public void reload() {
|
||||||
|
Lang.registerLangFile(this);
|
||||||
|
Lang.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedisIO getRedisIO() {
|
||||||
return redisIO;
|
return redisIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.io.yutian.elementoriginlib.command.handler.CommandHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -18,7 +17,6 @@ public class SimpleCommandManager implements ICommandManager {
|
||||||
protected static Map<String, Command> bukkitCommandMap = new HashMap<>();
|
protected static Map<String, Command> bukkitCommandMap = new HashMap<>();
|
||||||
protected static CommandMap commandMap;
|
protected static CommandMap commandMap;
|
||||||
|
|
||||||
private final Plugin plugin;
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -27,8 +25,7 @@ public class SimpleCommandManager implements ICommandManager {
|
||||||
private List<CommandEntity> commandEntities = new ArrayList<>();
|
private List<CommandEntity> commandEntities = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public SimpleCommandManager(@NotNull Plugin plugin, @NotNull String name) {
|
public SimpleCommandManager(@NotNull String name) {
|
||||||
this.plugin = plugin;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +59,6 @@ public class SimpleCommandManager implements ICommandManager {
|
||||||
Bukkit.getPluginCommand(commandName).setExecutor(new CommandHandler(this));
|
Bukkit.getPluginCommand(commandName).setExecutor(new CommandHandler(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -171,10 +171,6 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
int depth = args.length;
|
int depth = args.length;
|
||||||
String currentArg = args[depth - 1];
|
String currentArg = args[depth - 1];
|
||||||
|
|
||||||
// int index = depth - 1;
|
|
||||||
// if (commandEntity.getChildrens().size() == 1 && commandEntity.getChildrens().get(0).isNodal()) {
|
|
||||||
// index = depth - 2;
|
|
||||||
// }
|
|
||||||
return getSuggestions(sender, entries, args, 0, depth - 1, currentArg);
|
return getSuggestions(sender, entries, args, 0, depth - 1, currentArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ package com.io.yutian.elementoriginlib.command.list;
|
||||||
import com.io.yutian.elementoriginlib.command.CommandContext;
|
import com.io.yutian.elementoriginlib.command.CommandContext;
|
||||||
import com.io.yutian.elementoriginlib.command.CommandEntity;
|
import com.io.yutian.elementoriginlib.command.CommandEntity;
|
||||||
import com.io.yutian.elementoriginlib.command.CommandEntry;
|
import com.io.yutian.elementoriginlib.command.CommandEntry;
|
||||||
|
import com.io.yutian.elementoriginlib.command.ICommandManager;
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.Command;
|
import com.io.yutian.elementoriginlib.command.interfaces.Command;
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.Parameter;
|
import com.io.yutian.elementoriginlib.command.interfaces.Parameter;
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.SubCommand;
|
import com.io.yutian.elementoriginlib.command.interfaces.SubCommand;
|
||||||
import com.io.yutian.elementoriginlib.lang.Lang;
|
import com.io.yutian.elementoriginlib.lang.Lang;
|
||||||
import com.io.yutian.elementoriginlib.list.PageList;
|
import com.io.yutian.elementoriginlib.list.PageList;
|
||||||
import com.io.yutian.elementoriginlib.manager.CommandManager;
|
|
||||||
import com.io.yutian.elementoriginlib.util.ComponentBuilder;
|
import com.io.yutian.elementoriginlib.util.ComponentBuilder;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
@ -25,17 +25,16 @@ public class CommandHelp {
|
||||||
|
|
||||||
private final static int MAX_PAGE_SIZE = 8;
|
private final static int MAX_PAGE_SIZE = 8;
|
||||||
|
|
||||||
private final CommandManager commandManager;
|
private final ICommandManager commandManager;
|
||||||
private final String alias;
|
|
||||||
|
|
||||||
|
|
||||||
public CommandHelp(CommandManager commandManager, String alias) {
|
public CommandHelp(ICommandManager commandManager) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
this.alias = alias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand(nodal = true)
|
@SubCommand(nodal = true)
|
||||||
public void help(CommandContext commandContext, @Parameter(required = false, defaultValue = "1") int page) {
|
public void help(CommandContext commandContext, @Parameter(required = false, defaultValue = "1") int page) {
|
||||||
|
String alias = commandContext.getLabel();
|
||||||
String commandAlias = alias != null ? alias : commandContext.getLabel();
|
String commandAlias = alias != null ? alias : commandContext.getLabel();
|
||||||
CommandSender sender = commandContext.getSender();
|
CommandSender sender = commandContext.getSender();
|
||||||
if (page <= 0) {
|
if (page <= 0) {
|
||||||
|
@ -81,11 +80,12 @@ public class CommandHelp {
|
||||||
private StringBuilder getCommandInfo(CommandEntity command, String commandAlias) {
|
private StringBuilder getCommandInfo(CommandEntity command, String commandAlias) {
|
||||||
StringBuilder stringBuilder = new StringBuilder("§6/"+ commandAlias +" "+ command.getCommand());
|
StringBuilder stringBuilder = new StringBuilder("§6/"+ commandAlias +" "+ command.getCommand());
|
||||||
stringBuilder.append("§f");
|
stringBuilder.append("§f");
|
||||||
System.out.println(commandAlias);
|
|
||||||
if (command.getChildrens().size() > 0) {
|
if (command.getChildrens().size() > 0) {
|
||||||
|
if (!(command.getChildrens().size() == 1 && command.getChildrens().get(0).isNodal())) {
|
||||||
|
for (CommandEntry child : command.getChildrens()) {
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Optional<String> optional = Lang.getOptional("command."+command.getCommand()+".description");
|
Optional<String> optional = Lang.getOptional("command."+command.getCommand()+".description");
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.io.yutian.elementoriginlib.command.list;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.ElementOriginLib;
|
||||||
|
import com.io.yutian.elementoriginlib.command.CommandContext;
|
||||||
|
import com.io.yutian.elementoriginlib.command.interfaces.Command;
|
||||||
|
import com.io.yutian.elementoriginlib.command.interfaces.SubCommand;
|
||||||
|
import com.io.yutian.elementoriginlib.lang.Lang;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
@Command("reload")
|
||||||
|
public class CommandReload {
|
||||||
|
|
||||||
|
@SubCommand(value = "reload", nodal = true)
|
||||||
|
public void reload(CommandContext context) {
|
||||||
|
CommandSender sender = context.getSender();
|
||||||
|
ElementOriginLib.inst().reload();
|
||||||
|
sender.sendMessage(Lang.get("command.reload.success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,48 +0,0 @@
|
||||||
package com.io.yutian.elementoriginlib.command.list;
|
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.command.CommandContext;
|
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.Command;
|
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.SubCommand;
|
|
||||||
import com.io.yutian.elementoriginlib.command.interfaces.Parameter;
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItem;
|
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStats;
|
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.StringData;
|
|
||||||
import com.io.yutian.elementoriginlib.item.stat.list.IdStat;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
@Command("test")
|
|
||||||
public class CommandTest {
|
|
||||||
|
|
||||||
@SubCommand("list")
|
|
||||||
public void list(CommandContext context, @Parameter(required = false, defaultValue = "1") int page) {
|
|
||||||
System.out.println(context.getSender());
|
|
||||||
System.out.println("list:"+page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubCommand("item.get")
|
|
||||||
public void item_get(CommandContext context) {
|
|
||||||
Player player = (Player) context.getSender();
|
|
||||||
|
|
||||||
OriginItem originItem = new OriginItem(new ItemStack(Material.IRON_AXE));
|
|
||||||
originItem.setStatData(ItemStats.getItemStat(IdStat.class), new StringData("test"));
|
|
||||||
player.getInventory().addItem(originItem.getItemStack());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubCommand("item.load")
|
|
||||||
public void item_load(CommandContext context) {
|
|
||||||
Player player = (Player) context.getSender();
|
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
OriginItem originItem = new OriginItem(itemStack);
|
|
||||||
System.out.println(originItem.getStats());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubCommand("item.test")
|
|
||||||
public void item_test(@Parameter String id) {
|
|
||||||
System.out.println(id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,13 +8,13 @@ public class DataSyncHelper {
|
||||||
|
|
||||||
public static void saveData(String key, Object value) {
|
public static void saveData(String key, Object value) {
|
||||||
String strValue = SerializeHelper.serialize(value);
|
String strValue = SerializeHelper.serialize(value);
|
||||||
try (Jedis jedis = ElementOriginLib.getRedisIO().getJedisPool().getResource()) {
|
try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) {
|
||||||
jedis.set(key, strValue);
|
jedis.set(key, strValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getData(String key, Class<T> clazz) {
|
public static <T> T getData(String key, Class<T> clazz) {
|
||||||
try (Jedis jedis = ElementOriginLib.getRedisIO().getJedisPool().getResource()) {
|
try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) {
|
||||||
if (!jedis.exists(key)) {
|
if (!jedis.exists(key)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.io.yutian.elementoriginlib.exception.itemstat;
|
||||||
|
|
||||||
|
public class ItemStatDataLoadException extends RuntimeException {
|
||||||
|
|
||||||
|
public ItemStatDataLoadException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStatDataLoadException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStatDataLoadException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStatDataLoadException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,19 +9,19 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class OriginItem {
|
public class TagStatItem {
|
||||||
|
|
||||||
private ItemStack itemStack;
|
private ItemStack itemStack;
|
||||||
private ItemProxy itemProxy;
|
private ItemProxy itemProxy;
|
||||||
private Map<ItemStat, StatData> stats = new HashMap<>();
|
private Map<ItemStat, StatData> stats = new HashMap<>();
|
||||||
|
|
||||||
private OriginItemStackBuilder builder;
|
private TagStatItemStackBuilder builder;
|
||||||
|
|
||||||
public OriginItem(ItemStack itemStack) {
|
public TagStatItem(ItemStack itemStack) {
|
||||||
this.itemStack = itemStack;
|
this.itemStack = itemStack;
|
||||||
this.itemProxy = new ItemProxy(itemStack);
|
this.itemProxy = new ItemProxy(itemStack);
|
||||||
|
|
||||||
this.builder = new OriginItemStackBuilder(this);
|
this.builder = new TagStatItemStackBuilder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatData(@NotNull ItemStat stat, @NotNull StatData data) {
|
public void setStatData(@NotNull ItemStat stat, @NotNull StatData data) {
|
||||||
|
@ -53,7 +53,7 @@ public class OriginItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public OriginItemStackBuilder builder() {
|
public TagStatItemStackBuilder builder() {
|
||||||
return this.builder;
|
return this.builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,14 +85,14 @@ public class OriginItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OriginItem clone() {
|
public TagStatItem clone() {
|
||||||
OriginItem originItem = new OriginItem(itemStack.clone());
|
TagStatItem tagStatItem = new TagStatItem(itemStack.clone());
|
||||||
Iterator iterator = this.stats.keySet().iterator();
|
Iterator iterator = this.stats.keySet().iterator();
|
||||||
while(iterator.hasNext()) {
|
while(iterator.hasNext()) {
|
||||||
ItemStat itemStat = (ItemStat) iterator.next();
|
ItemStat itemStat = (ItemStat) iterator.next();
|
||||||
originItem.stats.put(itemStat, this.stats.get(itemStat));
|
tagStatItem.stats.put(itemStat, this.stats.get(itemStat));
|
||||||
}
|
}
|
||||||
return originItem;
|
return tagStatItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,28 +1,33 @@
|
||||||
package com.io.yutian.elementoriginlib.item;
|
package com.io.yutian.elementoriginlib.item;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
|
||||||
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagCompound;
|
||||||
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;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class OriginItemStackBuilder {
|
public class TagStatItemStackBuilder {
|
||||||
|
|
||||||
private final OriginItem originItem;
|
private final TagStatItem tagStatItem;
|
||||||
|
|
||||||
protected ItemStack itemStack;
|
protected ItemStack itemStack;
|
||||||
protected ItemMeta itemMeta;
|
protected ItemMeta itemMeta;
|
||||||
|
|
||||||
protected ItemProxy itemProxy;
|
protected ItemProxy itemProxy;
|
||||||
|
|
||||||
public OriginItemStackBuilder(OriginItem originItem) {
|
public TagStatItemStackBuilder(TagStatItem tagStatItem) {
|
||||||
this.originItem = originItem;
|
this.tagStatItem = tagStatItem;
|
||||||
this.itemStack = originItem.getItemStack();
|
this.itemStack = tagStatItem.getItemStack();
|
||||||
this.itemMeta = itemStack.getItemMeta();
|
this.itemMeta = itemStack.getItemMeta();
|
||||||
this.itemProxy = originItem.getItemProxy();
|
this.itemProxy = tagStatItem.getItemProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editTag(Consumer<TagCompound> tagCompoundConsumer) {
|
||||||
|
itemProxy.editTag(tagCompoundConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -37,23 +42,23 @@ public class OriginItemStackBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildCompounds() {
|
private void buildCompounds() {
|
||||||
originItem.getStats().forEach((stat, statData) -> stat.whenApplied(this, statData));
|
tagStatItem.getStats().forEach((stat, statData) -> stat.whenApplied(this, statData));
|
||||||
itemStack = itemProxy.getItemStack();
|
itemStack = itemProxy.getItemStack();
|
||||||
itemMeta = itemStack.getItemMeta();
|
itemMeta = itemStack.getItemMeta();
|
||||||
originItem.getStats().forEach((stat, statData) -> stat.applyMeta(this, statData));
|
tagStatItem.getStats().forEach((stat, statData) -> stat.applyMeta(this, statData));
|
||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
List<String> lores = itemMeta.hasLore() ? itemMeta.getLore() : new ArrayList<>();
|
List<String> lores = itemMeta.hasLore() ? itemMeta.getLore() : new ArrayList<>();
|
||||||
originItem.getStats().forEach((stat, statData) -> stat.whenApplyLore(this, statData, lores));
|
tagStatItem.getStats().forEach((stat, statData) -> stat.whenApplyLore(this, statData, lores));
|
||||||
itemStack.setLore(lores);
|
itemStack.setLore(lores);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ItemProxy getNBTItem() {
|
public ItemProxy getItemProxy() {
|
||||||
return itemProxy;
|
return itemProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OriginItem getOriginItem() {
|
public TagStatItem getOriginItem() {
|
||||||
return originItem;
|
return tagStatItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat;
|
package com.io.yutian.elementoriginlib.item.stat;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItem;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.item.TagStatItem;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -13,28 +14,33 @@ public abstract class ItemStat<S extends StatData> {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String id;
|
private final String id;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String nbtPath;
|
private final String tagPath;
|
||||||
|
|
||||||
public ItemStat(@NotNull String id, @NotNull String path) {
|
public ItemStat(@NotNull String id, @NotNull String path) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.nbtPath = path;
|
this.tagPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull S statData);
|
public abstract void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull S statData);
|
||||||
|
|
||||||
public void applyMeta(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull S statData) {
|
public abstract S loadAsObject(@NotNull Object value) throws ItemStatDataLoadException;
|
||||||
|
|
||||||
|
public void applyMeta(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull S statData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void whenApplyLore(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull S statData, @NotNull List<String> lores) {
|
public void whenApplyLore(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull S statData, @NotNull List<String> lores) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract S getLoadedNBT(@NotNull ItemProxy itemProxy);
|
public abstract S getLoadedTag(@NotNull ItemProxy itemProxy);
|
||||||
|
|
||||||
public void load(@NotNull OriginItem originItem) {
|
public void load(@NotNull TagStatItem tagStatItem) {
|
||||||
S loadedNBT = getLoadedNBT(originItem.getItemProxy());
|
if (!tagStatItem.getItemProxy().has(getTagPath())) {
|
||||||
if (loadedNBT != null) {
|
return;
|
||||||
originItem.setStatData(this, loadedNBT);
|
}
|
||||||
|
S loadedTag = getLoadedTag(tagStatItem.getItemProxy());
|
||||||
|
if (loadedTag != null) {
|
||||||
|
tagStatItem.setStatData(this, loadedTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +50,8 @@ public abstract class ItemStat<S extends StatData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getNBTPath() {
|
public String getTagPath() {
|
||||||
return nbtPath;
|
return tagPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,12 +16,13 @@ public class ItemStats {
|
||||||
private static Map<Class<? extends ItemStat>, ItemStat<?>> itemStats = new HashMap<>();
|
private static Map<Class<? extends ItemStat>, ItemStat<?>> itemStats = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register(IdStat.class, new IdStat());
|
register(new IdStat());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <I extends ItemStat> void register(Class<I> clazz, I itemStat) {
|
public static void register(ItemStat itemStat) {
|
||||||
|
Class<? extends ItemStat> clazz = itemStat.getClass();
|
||||||
if (itemStats.containsKey(itemStat.getId())) {
|
if (itemStats.containsKey(itemStat.getId())) {
|
||||||
LOGGER.warn("ItemStat "+clazz.getName()+" 已经注册过了");
|
LOGGER.warn("ItemStat "+clazz.getName()+" 已存在");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
itemStats.put(clazz, itemStat);
|
itemStats.put(clazz, itemStat);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat;
|
package com.io.yutian.elementoriginlib.item.stat;
|
||||||
|
|
||||||
public interface StatData {
|
public interface StatData<S> {
|
||||||
|
|
||||||
default boolean isEmpty() {
|
default boolean isEmpty() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.data;
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.Mergeable;
|
import com.io.yutian.elementoriginlib.item.stat.Mergeable;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DoubleListData extends ListData<Double> {
|
||||||
|
|
||||||
|
public DoubleListData(List<Double> list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class EnumData<E extends Enum> implements StatData {
|
||||||
|
|
||||||
|
private E value;
|
||||||
|
|
||||||
|
public EnumData(E value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public E getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(E value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return value == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EnumData{" +
|
||||||
|
"value=" + value +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
EnumData<?> enumData = (EnumData<?>) o;
|
||||||
|
return Objects.equals(value, enumData.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EnumListData<E extends Enum> extends ListData<E> {
|
||||||
|
|
||||||
|
public EnumListData(List<E> list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IntListData extends ListData<Integer> {
|
||||||
|
|
||||||
|
public IntListData(List<Integer> list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.Mergeable;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ListData<V> implements StatData, Mergeable<ListData<V>> {
|
||||||
|
|
||||||
|
private List<V> list;
|
||||||
|
|
||||||
|
public ListData(List<V> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<V> getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(V value) {
|
||||||
|
this.list.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void merge(ListData<V> var1) {
|
||||||
|
this.list.addAll(var1.getList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ListData<V> cloneData() {
|
||||||
|
return new ListData(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return list.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.data;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.Mergeable;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.StatData;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MapData implements StatData, Mergeable<MapData> {
|
||||||
|
|
||||||
|
private Map<String, Object> map;
|
||||||
|
|
||||||
|
public MapData(Map<String, Object> map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(String key) {
|
||||||
|
return map.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOrDefault(String key, Object defaultValue) {
|
||||||
|
return map.getOrDefault(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(String key, Object value) {
|
||||||
|
map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(String key) {
|
||||||
|
map.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(String key) {
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void merge(MapData var1) {
|
||||||
|
this.map.putAll(var1.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull MapData cloneData() {
|
||||||
|
return new MapData(this.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return map.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,36 +6,10 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StringListData implements StatData, Mergeable<StringListData> {
|
public class StringListData extends ListData<String> {
|
||||||
|
|
||||||
private List<String> list;
|
|
||||||
|
|
||||||
public StringListData(List<String> list) {
|
public StringListData(List<String> list) {
|
||||||
this.list = list;
|
super(list);
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getList() {
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(String str) {
|
|
||||||
this.list.add(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void merge(StringListData var1) {
|
|
||||||
this.list.addAll(var1.getList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public StringListData cloneData() {
|
|
||||||
return new StringListData(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return list.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.BooleanData;
|
import com.io.yutian.elementoriginlib.item.stat.data.BooleanData;
|
||||||
import com.io.yutian.elementoriginlib.tag.TagByte;
|
import com.io.yutian.elementoriginlib.tag.TagByte;
|
||||||
|
@ -8,6 +9,8 @@ import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class BooleanStat extends ItemStat<BooleanData> {
|
public abstract class BooleanStat extends ItemStat<BooleanData> {
|
||||||
|
|
||||||
public BooleanStat(@NotNull String id, @NotNull String path) {
|
public BooleanStat(@NotNull String id, @NotNull String path) {
|
||||||
|
@ -15,15 +18,41 @@ public abstract class BooleanStat extends ItemStat<BooleanData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull BooleanData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull BooleanData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.putByte(getNBTPath(), (byte) (statData.getValue() ? 1 : 0)));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putByte(getTagPath(), (byte) (statData.getValue() ? 1 : 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BooleanData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof Boolean bool) {
|
||||||
|
return new BooleanData(bool);
|
||||||
|
} else if (value instanceof String arg) {
|
||||||
|
boolean parsed = Boolean.parseBoolean(arg);
|
||||||
|
if (!arg.equalsIgnoreCase("true") && !arg.equalsIgnoreCase("false")) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid boolean string: " + arg);
|
||||||
|
}
|
||||||
|
return new BooleanData(parsed);
|
||||||
|
} else if (value instanceof Byte b) {
|
||||||
|
return new BooleanData(b == 1);
|
||||||
|
} else if (value instanceof Integer i) {
|
||||||
|
return new BooleanData(i == 1);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid boolean value: " + value);
|
||||||
|
}
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid type: " + value.getClass(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BooleanData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public BooleanData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
return new BooleanData(((TagByte) itemProxy.get(getNBTPath())).getByte() == 1);
|
return new BooleanData(((TagByte) itemProxy.get(getTagPath())).getByte() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.data.DoubleListData;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagDouble;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public abstract class DoubleListStat extends ItemStat<DoubleListData> {
|
||||||
|
|
||||||
|
public DoubleListStat(@NotNull String id, @NotNull String path) {
|
||||||
|
super(id, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull DoubleListData statData) {
|
||||||
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
|
TagList<TagDouble> tagList = new TagList<>();
|
||||||
|
statData.getList().forEach(s -> tagList.add(new TagDouble(s)));
|
||||||
|
itemProxy.editTag(tagCompound1 -> tagCompound1.put(getTagPath(), tagList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DoubleListData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof List<?> list) {
|
||||||
|
List<Double> doubleList = new ArrayList<>();
|
||||||
|
for (Object item : list) {
|
||||||
|
if (item instanceof Double d) {
|
||||||
|
doubleList.add(d);
|
||||||
|
} else if (item instanceof String str) {
|
||||||
|
// 如果是 String,尝试将其解析为 Double
|
||||||
|
try {
|
||||||
|
doubleList.add(Double.parseDouble(str));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid string value for Double: " + str, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("List contains non-double element: " + item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DoubleListData(doubleList);
|
||||||
|
} else if (value instanceof double[] array) {
|
||||||
|
List<Double> doubleList = new ArrayList<>();
|
||||||
|
for (double d : array) {
|
||||||
|
doubleList.add(d);
|
||||||
|
}
|
||||||
|
return new DoubleListData(doubleList);
|
||||||
|
} else if (value instanceof Double[] array) {
|
||||||
|
List<Double> doubleList = new ArrayList<>(Arrays.asList(array));
|
||||||
|
return new DoubleListData(doubleList);
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
List<Double> doubleList = new ArrayList<>();
|
||||||
|
String[] items = str.split(",");
|
||||||
|
for (String item : items) {
|
||||||
|
try {
|
||||||
|
doubleList.add(Double.parseDouble(item.trim()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid number format in string: " + item, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DoubleListData(doubleList);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for DoubleListData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public DoubleListData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
|
if (!itemProxy.has(getTagPath(), TagList.TYPE_ID)) {
|
||||||
|
return new DoubleListData(new ArrayList<>());
|
||||||
|
}
|
||||||
|
TagList<TagDouble> tagList = (TagList<TagDouble>) itemProxy.get(getTagPath());
|
||||||
|
List<Double> list = new ArrayList<>();
|
||||||
|
for (int i = 0; i < tagList.size(); i++) {
|
||||||
|
list.add(tagList.get(i).getDouble());
|
||||||
|
}
|
||||||
|
return new DoubleListData(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.DoubleData;
|
import com.io.yutian.elementoriginlib.item.stat.data.DoubleData;
|
||||||
import com.io.yutian.elementoriginlib.tag.TagDouble;
|
import com.io.yutian.elementoriginlib.tag.TagDouble;
|
||||||
|
@ -8,6 +9,8 @@ import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class DoubleStat extends ItemStat<DoubleData> {
|
public abstract class DoubleStat extends ItemStat<DoubleData> {
|
||||||
|
|
||||||
public DoubleStat(@NotNull String id, @NotNull String path) {
|
public DoubleStat(@NotNull String id, @NotNull String path) {
|
||||||
|
@ -15,15 +18,43 @@ public abstract class DoubleStat extends ItemStat<DoubleData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull DoubleData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull DoubleData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.putDouble(getNBTPath(), statData.getValue()));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putDouble(getTagPath(), statData.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DoubleData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof Double d) {
|
||||||
|
return new DoubleData(d);
|
||||||
|
} else if (value instanceof String arg) {
|
||||||
|
try {
|
||||||
|
return new DoubleData(Double.parseDouble(arg));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid double string: " + arg, e);
|
||||||
|
}
|
||||||
|
} else if (value instanceof Byte b) {
|
||||||
|
return new DoubleData((double) b);
|
||||||
|
} else if (value instanceof Integer i) {
|
||||||
|
return new DoubleData((double) i);
|
||||||
|
} else if (value instanceof Long l) {
|
||||||
|
return new DoubleData((double) l);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid double value: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public DoubleData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public DoubleData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
return new DoubleData(((TagDouble) itemProxy.get(getNBTPath())).getDouble());
|
return new DoubleData(((TagDouble) itemProxy.get(getTagPath())).getDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.data.EnumListData;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagList;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagString;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class EnumListStat<E extends Enum> extends ItemStat<EnumListData<E>> {
|
||||||
|
|
||||||
|
private Class<E> clazz;
|
||||||
|
|
||||||
|
public EnumListStat(@NotNull String id, @NotNull String path, Class<E> clazz) {
|
||||||
|
super(id, path);
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull EnumListData<E> statData) {
|
||||||
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
|
TagList<TagString> tagList = new TagList<>();
|
||||||
|
statData.getList().forEach(s -> tagList.add(new TagString(s.name())));
|
||||||
|
itemProxy.editTag(tagCompound1 -> tagCompound1.put(getTagPath(), tagList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumListData<E> loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof List<?> list) {
|
||||||
|
List<E> enumList = new ArrayList<>();
|
||||||
|
for (Object item : list) {
|
||||||
|
if (item instanceof String str) {
|
||||||
|
try {
|
||||||
|
E enumConstant = (E) Enum.valueOf(clazz, str);
|
||||||
|
enumList.add(enumConstant);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid enum string: " + str, e);
|
||||||
|
}
|
||||||
|
} else if (item instanceof Integer i) {
|
||||||
|
E[] enumConstants = clazz.getEnumConstants();
|
||||||
|
if (i < 0 || i >= enumConstants.length) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid enum ordinal: " + i);
|
||||||
|
}
|
||||||
|
enumList.add(enumConstants[i]);
|
||||||
|
} else if (item instanceof Enum<?> enumItem) {
|
||||||
|
enumList.add((E) enumItem);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid list element type: " + item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EnumListData<>(enumList);
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
List<E> enumList = new ArrayList<>();
|
||||||
|
String[] enumNames = str.split(",");
|
||||||
|
for (String enumName : enumNames) {
|
||||||
|
try {
|
||||||
|
E enumConstant = (E) Enum.valueOf(clazz, enumName.trim());
|
||||||
|
enumList.add(enumConstant);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid enum string: " + enumName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EnumListData<>(enumList);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for EnumListData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable EnumListData<E> getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
|
if (!itemProxy.has(getTagPath(), TagList.TYPE_ID)) {
|
||||||
|
return new EnumListData<>(new ArrayList<>());
|
||||||
|
}
|
||||||
|
TagList<TagString> tagList = (TagList<TagString>) itemProxy.get(getTagPath());
|
||||||
|
List<Enum> list = new ArrayList<>();
|
||||||
|
for (int i = 0; i < tagList.size(); i++) {
|
||||||
|
list.add(Enum.valueOf(clazz, tagList.get(i).getString()));
|
||||||
|
}
|
||||||
|
return new EnumListData(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.data.EnumData;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagString;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public abstract class EnumStat<E extends Enum> extends ItemStat<EnumData<E>> {
|
||||||
|
|
||||||
|
private Class<E> clazz;
|
||||||
|
|
||||||
|
public EnumStat(@NotNull String id, @NotNull String path, Class<E> clazz) {
|
||||||
|
super(id, path);
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull EnumData<E> statData) {
|
||||||
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putString(getTagPath(), statData.getValue().name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumData<E> loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof Enum<?> enumValue) {
|
||||||
|
return new EnumData<>((E) enumValue);
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
try {
|
||||||
|
E enumConstant = (E) Enum.valueOf(clazz, str);
|
||||||
|
return new EnumData<>(enumConstant);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid enum string: " + str, e);
|
||||||
|
}
|
||||||
|
} else if (value instanceof Integer i) {
|
||||||
|
E[] enumConstants = clazz.getEnumConstants();
|
||||||
|
if (i < 0 || i >= enumConstants.length) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid enum ordinal: " + i);
|
||||||
|
}
|
||||||
|
return new EnumData<>(enumConstants[i]);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for EnumData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable EnumData<E> getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
|
return new EnumData(Enum.valueOf(clazz, ((TagString) itemProxy.get(getTagPath())).getString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.data.IntListData;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagInt;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.TagList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public abstract class IntListStat extends ItemStat<IntListData> {
|
||||||
|
|
||||||
|
public IntListStat(@NotNull String id, @NotNull String path) {
|
||||||
|
super(id, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull IntListData statData) {
|
||||||
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
|
TagList<TagInt> tagList = new TagList<>();
|
||||||
|
statData.getList().forEach(s -> tagList.add(new TagInt(s)));
|
||||||
|
itemProxy.editTag(tagCompound1 -> tagCompound1.put(getTagPath(), tagList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntListData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof List<?> list) {
|
||||||
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
for (Object item : list) {
|
||||||
|
if (item instanceof Integer i) {
|
||||||
|
intList.add(i);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("List contains non-integer element: " + item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new IntListData(intList);
|
||||||
|
} else if (value instanceof int[] array) {
|
||||||
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
for (int i : array) {
|
||||||
|
intList.add(i);
|
||||||
|
}
|
||||||
|
return new IntListData(intList);
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
try {
|
||||||
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
String[] items = str.split(",");
|
||||||
|
for (String item : items) {
|
||||||
|
intList.add(Integer.parseInt(item.trim()));
|
||||||
|
}
|
||||||
|
return new IntListData(intList);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid integer string: " + str, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for IntListData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IntListData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
|
if (!itemProxy.has(getTagPath(), TagList.TYPE_ID)) {
|
||||||
|
return new IntListData(new ArrayList<>());
|
||||||
|
}
|
||||||
|
TagList<TagInt> tagList = (TagList<TagInt>) itemProxy.get(getTagPath());
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
for (int i = 0; i < tagList.size(); i++) {
|
||||||
|
list.add(tagList.get(i).getInt());
|
||||||
|
}
|
||||||
|
return new IntListData(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.IntData;
|
import com.io.yutian.elementoriginlib.item.stat.data.IntData;
|
||||||
import com.io.yutian.elementoriginlib.tag.TagInt;
|
import com.io.yutian.elementoriginlib.tag.TagInt;
|
||||||
|
@ -8,6 +9,8 @@ import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class IntStat extends ItemStat<IntData> {
|
public abstract class IntStat extends ItemStat<IntData> {
|
||||||
|
|
||||||
public IntStat(@NotNull String id, @NotNull String path) {
|
public IntStat(@NotNull String id, @NotNull String path) {
|
||||||
|
@ -15,15 +18,57 @@ public abstract class IntStat extends ItemStat<IntData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull IntData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull IntData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.putInt(getNBTPath(), statData.getInt()));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putInt(getTagPath(), statData.getInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof Integer i) {
|
||||||
|
return new IntData(i);
|
||||||
|
} else if (value instanceof String arg) {
|
||||||
|
try {
|
||||||
|
return new IntData(Integer.parseInt(arg));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid integer string: " + arg, e);
|
||||||
|
}
|
||||||
|
} else if (value instanceof Byte b) {
|
||||||
|
return new IntData((int) b);
|
||||||
|
} else if (value instanceof Long l) {
|
||||||
|
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
|
||||||
|
throw new ItemStatDataLoadException("Long value out of range for integer: " + l);
|
||||||
|
}
|
||||||
|
return new IntData(l.intValue());
|
||||||
|
} else if (value instanceof Double d) {
|
||||||
|
if (d < Integer.MIN_VALUE || d > Integer.MAX_VALUE) {
|
||||||
|
throw new ItemStatDataLoadException("Double value out of range for integer: " + d);
|
||||||
|
}
|
||||||
|
return new IntData((int) d.doubleValue());
|
||||||
|
} else if (value instanceof Float f) {
|
||||||
|
if (f < Integer.MIN_VALUE || f > Integer.MAX_VALUE) {
|
||||||
|
throw new ItemStatDataLoadException("Float value out of range for integer: " + f);
|
||||||
|
}
|
||||||
|
return new IntData((int) f.floatValue());
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid integer value: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IntData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public IntData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
return new IntData(((TagInt) itemProxy.get(getNBTPath())).getInt());
|
return new IntData(((TagInt) itemProxy.get(getTagPath())).getInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
|
import com.io.yutian.elementoriginlib.item.stat.data.MapData;
|
||||||
|
import com.io.yutian.elementoriginlib.tag.*;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class MapStat extends ItemStat<MapData> {
|
||||||
|
|
||||||
|
public MapStat(@NotNull String id, @NotNull String path) {
|
||||||
|
super(id, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull MapData statData) {
|
||||||
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
|
TagCompound tagCompound = new TagCompound();
|
||||||
|
for (Map.Entry<String, Object> entry : statData.getMap().entrySet()) {
|
||||||
|
tagCompound.put(entry.getKey(), ITag.asObject(entry.getValue()));
|
||||||
|
}
|
||||||
|
itemProxy.editTag(tagCompound1 -> tagCompound1.put(getTagPath(), tagCompound));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof Map<?, ?> map) {
|
||||||
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof String key) {
|
||||||
|
resultMap.put(key, entry.getValue());
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Map key is not a String: " + entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new MapData(resultMap);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for MapData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable MapData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
|
if (!itemProxy.has(getTagPath(), TagCompound.TYPE_ID)) {
|
||||||
|
return new MapData(new HashMap<>());
|
||||||
|
}
|
||||||
|
TagCompound tagCompound = (TagCompound) itemProxy.get(getTagPath());
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
for (Map.Entry<String, ITag> entry : tagCompound.getMap().entrySet()) {
|
||||||
|
map.put(entry.getKey(), entry.getValue().getValue());
|
||||||
|
}
|
||||||
|
return new MapData(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.StringListData;
|
import com.io.yutian.elementoriginlib.item.stat.data.StringListData;
|
||||||
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
@ -10,7 +11,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class StringListStat extends ItemStat<StringListData> {
|
public abstract class StringListStat extends ItemStat<StringListData> {
|
||||||
|
|
||||||
|
@ -19,20 +22,52 @@ public abstract class StringListStat extends ItemStat<StringListData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull StringListData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull StringListData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
TagList<TagString> tagList = new TagList<>();
|
TagList<TagString> tagList = new TagList<>();
|
||||||
statData.getList().forEach(s -> tagList.add(new TagString(s)));
|
statData.getList().forEach(s -> tagList.add(new TagString(s)));
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.put(getNBTPath(), tagList));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.put(getTagPath(), tagList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringListData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof List<?> list) {
|
||||||
|
List<String> stringList = new ArrayList<>();
|
||||||
|
for (Object item : list) {
|
||||||
|
if (item instanceof String str) {
|
||||||
|
stringList.add(str);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("List contains non-string element: " + item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new StringListData(stringList);
|
||||||
|
} else if (value instanceof String[] array) {
|
||||||
|
// 处理 String[] 类型
|
||||||
|
return new StringListData(Arrays.asList(array));
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
List<String> stringList = new ArrayList<>();
|
||||||
|
stringList.add(str);
|
||||||
|
return new StringListData(stringList);
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value type for StringListData: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public StringListData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public StringListData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
if (!itemProxy.has(getNBTPath(), TagList.TYPE_ID)) {
|
if (!itemProxy.has(getTagPath(), TagList.TYPE_ID)) {
|
||||||
return new StringListData(new ArrayList<>());
|
return new StringListData(new ArrayList<>());
|
||||||
}
|
}
|
||||||
TagList<TagString> tagList = (TagList<TagString>) itemProxy.get(getNBTPath());
|
TagList<TagString> tagList = (TagList<TagString>) itemProxy.get(getTagPath());
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
for (int i = 0; i < tagList.size(); i++) {
|
for (int i = 0; i < tagList.size(); i++) {
|
||||||
list.add(tagList.get(i).getString());
|
list.add(tagList.get(i).getString());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.StringData;
|
import com.io.yutian.elementoriginlib.item.stat.data.StringData;
|
||||||
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
@ -8,6 +9,8 @@ import com.io.yutian.elementoriginlib.tag.TagString;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class StringStat extends ItemStat<StringData> {
|
public abstract class StringStat extends ItemStat<StringData> {
|
||||||
|
|
||||||
public StringStat(@NotNull String id, @NotNull String path) {
|
public StringStat(@NotNull String id, @NotNull String path) {
|
||||||
|
@ -15,16 +18,23 @@ public abstract class StringStat extends ItemStat<StringData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull StringData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull StringData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.putString(getNBTPath(), statData.getString()));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putString(getTagPath(), statData.getString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringData loadAsObject(@NotNull Object value) {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
return new StringData(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public StringData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public StringData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
return new StringData(((TagString) itemProxy.get(getNBTPath())).getString());
|
return new StringData(((TagString) itemProxy.get(getTagPath())).getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.io.yutian.elementoriginlib.item.stat.type;
|
package com.io.yutian.elementoriginlib.item.stat.type;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.item.OriginItemStackBuilder;
|
import com.io.yutian.elementoriginlib.exception.itemstat.ItemStatDataLoadException;
|
||||||
|
import com.io.yutian.elementoriginlib.item.TagStatItemStackBuilder;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
import com.io.yutian.elementoriginlib.item.stat.ItemStat;
|
||||||
import com.io.yutian.elementoriginlib.item.stat.data.UUIDData;
|
import com.io.yutian.elementoriginlib.item.stat.data.UUIDData;
|
||||||
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
import com.io.yutian.elementoriginlib.tag.ItemProxy;
|
||||||
|
@ -8,6 +9,7 @@ import com.io.yutian.elementoriginlib.tag.TagString;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class UUIDStat extends ItemStat<UUIDData> {
|
public abstract class UUIDStat extends ItemStat<UUIDData> {
|
||||||
|
@ -17,15 +19,37 @@ public abstract class UUIDStat extends ItemStat<UUIDData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull OriginItemStackBuilder itemStackBuilder, @NotNull UUIDData statData) {
|
public void whenApplied(@NotNull TagStatItemStackBuilder itemStackBuilder, @NotNull UUIDData statData) {
|
||||||
ItemProxy itemProxy = itemStackBuilder.getNBTItem();
|
ItemProxy itemProxy = itemStackBuilder.getItemProxy();
|
||||||
itemProxy.editTag(nbtCompound -> nbtCompound.putString(getNBTPath(), statData.getUUID().toString()));
|
itemProxy.editTag(tagCompound1 -> tagCompound1.putString(getTagPath(), statData.getUUID().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUIDData loadAsObject(@NotNull Object value) throws ItemStatDataLoadException {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid value: null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value instanceof UUID uuid) {
|
||||||
|
return new UUIDData(uuid);
|
||||||
|
} else if (value instanceof String str) {
|
||||||
|
try {
|
||||||
|
return new UUIDData(UUID.fromString(str));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ItemStatDataLoadException("Invalid UUID string: " + str, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ItemStatDataLoadException("Invalid UUID value: " + value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ItemStatDataLoadException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public UUIDData getLoadedNBT(@NotNull ItemProxy itemProxy) {
|
public UUIDData getLoadedTag(@NotNull ItemProxy itemProxy) {
|
||||||
return new UUIDData(UUID.fromString(((TagString) itemProxy.get(getNBTPath())).getString()));
|
return new UUIDData(UUID.fromString(((TagString) itemProxy.get(getTagPath())).getString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.io.yutian.elementoriginlib.logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
|
@ -44,14 +46,38 @@ public class Logger {
|
||||||
Bukkit.getLogger().warning(getPrefix("WARN") + msg);
|
Bukkit.getLogger().warning(getPrefix("WARN") + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void warn(String msg, Throwable throwable) {
|
||||||
|
Bukkit.getLogger().severe(getPrefix("WARN") + msg);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
throwable.printStackTrace(pw);
|
||||||
|
Bukkit.getLogger().severe(sw.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void error(String msg) {
|
public void error(String msg) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, getPrefix("ERROR") + msg);
|
Bukkit.getLogger().log(Level.SEVERE, getPrefix("ERROR") + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void error(String msg, Throwable throwable) {
|
||||||
|
Bukkit.getLogger().severe(getPrefix("ERROR") + msg);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
throwable.printStackTrace(pw);
|
||||||
|
Bukkit.getLogger().severe(sw.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void fatal(String msg) {
|
public void fatal(String msg) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "[!!!] "+getPrefix("FATAL") + msg);
|
Bukkit.getLogger().log(Level.SEVERE, "[!!!] "+getPrefix("FATAL") + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fatal(String msg, Throwable throwable) {
|
||||||
|
Bukkit.getLogger().severe("[!!!] "+getPrefix("FATAL") + msg);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
throwable.printStackTrace(pw);
|
||||||
|
Bukkit.getLogger().severe(sw.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void debug(String msg) {
|
public void debug(String msg) {
|
||||||
Bukkit.getLogger().finer(getPrefix("DEBUG") + msg);
|
Bukkit.getLogger().finer(getPrefix("DEBUG") + msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,17 @@ package com.io.yutian.elementoriginlib.manager;
|
||||||
|
|
||||||
import com.io.yutian.elementoriginlib.command.SimpleCommandManager;
|
import com.io.yutian.elementoriginlib.command.SimpleCommandManager;
|
||||||
import com.io.yutian.elementoriginlib.command.list.CommandHelp;
|
import com.io.yutian.elementoriginlib.command.list.CommandHelp;
|
||||||
import com.io.yutian.elementoriginlib.command.list.CommandTest;
|
import com.io.yutian.elementoriginlib.command.list.CommandReload;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class CommandManager extends SimpleCommandManager {
|
public class CommandManager extends SimpleCommandManager {
|
||||||
|
|
||||||
public CommandManager(Plugin plugin) {
|
public static final CommandManager INSTANCE = new CommandManager();
|
||||||
super(plugin, "elementoriginlib");
|
|
||||||
register(new CommandHelp(this, "help"));
|
public CommandManager() {
|
||||||
register(new CommandTest());
|
super("ElementOriginLib");
|
||||||
|
register(new CommandHelp(this));
|
||||||
|
register(new CommandReload());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,11 @@ command:
|
||||||
player-no-online: "&f玩家 &e$0 &f不存在或不在线"
|
player-no-online: "&f玩家 &e$0 &f不存在或不在线"
|
||||||
no-permission: "&f你没有执行该命令的权限"
|
no-permission: "&f你没有执行该命令的权限"
|
||||||
help:
|
help:
|
||||||
description: "获得指令帮助"
|
description: "&f获得指令帮助"
|
||||||
page-error: "页码错误"
|
page-error: "&c页码错误"
|
||||||
|
reload:
|
||||||
|
description: "&f重载配置文件"
|
||||||
|
success: "&a成功重载配置文件"
|
||||||
playerchatinput:
|
playerchatinput:
|
||||||
timeout: "&c输入超时"
|
timeout: "&c输入超时"
|
||||||
cancel: "&c输入已取消"
|
cancel: "&c输入已取消"
|
Loading…
Reference in New Issue
Block a user