From 0509f4f63eedd25ad3d4dfd13a91162742ed94df Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 30 Sep 2019 16:47:47 -0700 Subject: [PATCH 01/20] Starting work on reading NBT --- .../nossr50/listeners/PlayerListener.java | 15 +++++++++ .../gmail/nossr50/util/nbt/NBTManager.java | 32 +++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 43fe8a0bd..660c1c450 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -15,6 +15,7 @@ import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.ChimaeraWing; +import com.gmail.nossr50.util.nbt.NBTManager; import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -898,4 +899,18 @@ public class PlayerListener implements Listener { } } } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDebugPlayerInteract(PlayerInteractEvent event) { + if(pluginRef.getUserManager().getPlayer(event.getPlayer()) != null) { + McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(event.getPlayer()); + if(mcMMOPlayer.isDebugMode()) { + switch(event.getAction()) { + case LEFT_CLICK_AIR: + case LEFT_CLICK_BLOCK: + NBTManager.debugNBTInMainHandItem(event.getPlayer()); + } + } + } + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index e620486b2..ab0385e2d 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -4,10 +4,11 @@ package com.gmail.nossr50.util.nbt; import net.minecraft.server.v1_14_R1.NBTBase; import net.minecraft.server.v1_14_R1.NBTList; import net.minecraft.server.v1_14_R1.NBTTagCompound; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.checkerframework.checker.nullness.qual.Nullable; public class NBTManager { @@ -26,11 +27,26 @@ public class NBTManager { } } + public static void debugNBTInMainHandItem(Player player) { + player.sendMessage("Starting NBT Debug Dump..."); + ItemStack itemStack = player.getInventory().getItemInMainHand(); + player.sendMessage("Checking NBT for "+itemStack.toString()); + NBTTagCompound nbtTagCompound = getNBT(itemStack); + + if(nbtTagCompound == null) { + player.sendMessage("No NBT data found for main hand item."); + return; + } + + player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size()); + printNBT(nbtTagCompound, player); + player.sendMessage("-- END OF NBT REPORT --"); + } + + @Nullable public static NBTTagCompound getNBT(ItemStack itemStack) { - Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString()); net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound rootTag = nmsItemStack.getTag(); - return rootTag; + return nmsItemStack.getTag(); } public static NBTBase constructNBT(String nbtString) { @@ -43,9 +59,11 @@ public class NBTManager { } } - public static void printNBT(ItemStack itemStack) { - for(String key : getNBT(itemStack).getKeys()) { - Bukkit.broadcastMessage("NBT Key found: "+key); + public static void printNBT(NBTTagCompound nbtTagCompound, Player player) { + for(String key : nbtTagCompound.getKeys()) { + player.sendMessage(""); + player.sendMessage("NBT Key: "+key); + player.sendMessage("NBT Value: " + nbtTagCompound.get(key).asString()); } } From 433f6d085d6549ac1763d897ee72f2468d399e90 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 30 Sep 2019 17:53:57 -0700 Subject: [PATCH 02/20] Time for a break --- .../gmail/nossr50/util/nbt/NBTManager.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index ab0385e2d..aa3da4416 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -1,9 +1,11 @@ package com.gmail.nossr50.util.nbt; +import net.minecraft.server.v1_14_R1.Item; import net.minecraft.server.v1_14_R1.NBTBase; import net.minecraft.server.v1_14_R1.NBTList; import net.minecraft.server.v1_14_R1.NBTTagCompound; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer; import org.bukkit.entity.Player; @@ -41,6 +43,29 @@ public class NBTManager { player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size()); printNBT(nbtTagCompound, player); player.sendMessage("-- END OF NBT REPORT --"); + + player.sendMessage("Attempting to add NBT key named - Herp"); + addFloatNBT(nbtTagCompound, "herp", 13.37F); + + player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size()); + printNBT(nbtTagCompound, player); + player.sendMessage("-- END OF NBT REPORT --"); + + player.sendMessage("Attempting to save NBT data..."); + player.getInventory().setItemInMainHand(saveNBT(itemStack, nbtTagCompound)); + player.updateInventory(); + } + + public static ItemStack saveNBT(ItemStack itemStack, NBTTagCompound nbtTagCompound) { + net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = getNMSItemStack(itemStack); + nmsItemStack.save(nbtTagCompound); + CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsItemStack); + itemStack.setItemMeta(craftItemStack.getItemMeta()); + return itemStack; + } + + public static net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) { + return CraftItemStack.asNMSCopy(itemStack); } @Nullable @@ -49,6 +74,10 @@ public class NBTManager { return nmsItemStack.getTag(); } + public static void addFloatNBT(NBTTagCompound nbtTagCompound, String key, float value) { + nbtTagCompound.setFloat(key, value); + } + public static NBTBase constructNBT(String nbtString) { try { return CraftNBTTagConfigSerializer.deserialize(nbtString); From 6e0f8f99fa2b4c2cb2fc3b0a818fb439177afa62 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 15:44:58 -0700 Subject: [PATCH 03/20] Progress? --- .../gmail/nossr50/util/nbt/NBTManager.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index aa3da4416..87916ad46 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -12,6 +12,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + public class NBTManager { private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem"; @@ -58,9 +61,19 @@ public class NBTManager { public static ItemStack saveNBT(ItemStack itemStack, NBTTagCompound nbtTagCompound) { net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = getNMSItemStack(itemStack); - nmsItemStack.save(nbtTagCompound); - CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsItemStack); - itemStack.setItemMeta(craftItemStack.getItemMeta()); + + try { + Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack"); + Class[] methodParameters = new Class[]{ NBTTagCompound.class }; + Method loadMethod = clazz.getDeclaredMethod("load", methodParameters); + loadMethod.setAccessible(true); + loadMethod.invoke(nmsItemStack, nbtTagCompound); + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + +// nmsItemStack.save(nbtTagCompound); +// itemStack.setItemMeta(nmsItemStack..getItemMeta()); return itemStack; } From 8febe2d0bdff466ac2d9bc2d6b579a8fc891a840 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 16:19:15 -0700 Subject: [PATCH 04/20] Progress?? --- .../nossr50/listeners/PlayerListener.java | 3 +- .../main/java/com/gmail/nossr50/mcMMO.java | 9 +- .../gmail/nossr50/util/nbt/NBTManager.java | 88 ++++++++++--------- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 660c1c450..2ce1ed1c0 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -15,7 +15,6 @@ import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.ChimaeraWing; -import com.gmail.nossr50.util.nbt.NBTManager; import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -908,7 +907,7 @@ public class PlayerListener implements Listener { switch(event.getAction()) { case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: - NBTManager.debugNBTInMainHandItem(event.getPlayer()); + pluginRef.getNbtManager().debugNBTInMainHandItem(event.getPlayer()); } } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java index 75ad07e5d..f6d49b4f8 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -33,6 +33,7 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.commands.CommandTools; import com.gmail.nossr50.util.experience.FormulaManager; +import com.gmail.nossr50.util.nbt.NBTManager; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.PlayerLevelTools; import com.gmail.nossr50.util.player.UserManager; @@ -75,7 +76,7 @@ public class mcMMO extends JavaPlugin { private FormulaManager formulaManager; private NotificationManager notificationManager; private CommandRegistrationManager commandRegistrationManager; -// private NBTManager nbtManager; + private NBTManager nbtManager; private PartyManager partyManager; private LocaleManager localeManager; private ChatManager chatManager; @@ -212,7 +213,7 @@ public class mcMMO extends JavaPlugin { commandRegistrationManager = new CommandRegistrationManager(this); commandRegistrationManager.registerCommands(); -// nbtManager = new NBTManager(); + nbtManager = new NBTManager(); //Init Chunk Manager Factory chunkManagerFactory = new ChunkManagerFactory(this); @@ -857,4 +858,8 @@ public class mcMMO extends JavaPlugin { public PerkUtils getPerkUtils() { return perkUtils; } + + public NBTManager getNbtManager() { + return nbtManager; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index 87916ad46..e3830438f 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -1,23 +1,21 @@ package com.gmail.nossr50.util.nbt; -import net.minecraft.server.v1_14_R1.Item; import net.minecraft.server.v1_14_R1.NBTBase; import net.minecraft.server.v1_14_R1.NBTList; import net.minecraft.server.v1_14_R1.NBTTagCompound; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.checker.nullness.qual.NonNull; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class NBTManager { - private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem"; + private final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem"; private Class craftMetaItemClass; public NBTManager() { @@ -25,42 +23,68 @@ public class NBTManager { } private void init() { - try { - Class craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } +// try { +// Class craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); +// } } - public static void debugNBTInMainHandItem(Player player) { + public void debugNBTInMainHandItem(Player player) { player.sendMessage("Starting NBT Debug Dump..."); ItemStack itemStack = player.getInventory().getItemInMainHand(); player.sendMessage("Checking NBT for "+itemStack.toString()); - NBTTagCompound nbtTagCompound = getNBT(itemStack); - - if(nbtTagCompound == null) { - player.sendMessage("No NBT data found for main hand item."); - return; - } + NBTTagCompound nbtTagCompound = getNBTCopy(itemStack); player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size()); printNBT(nbtTagCompound, player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to add NBT key named - Herp"); - addFloatNBT(nbtTagCompound, "herp", 13.37F); + addFloatNBT(itemStack, "herp", 13.37F); player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size()); printNBT(nbtTagCompound, player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to save NBT data..."); - player.getInventory().setItemInMainHand(saveNBT(itemStack, nbtTagCompound)); player.updateInventory(); } - public static ItemStack saveNBT(ItemStack itemStack, NBTTagCompound nbtTagCompound) { - net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = getNMSItemStack(itemStack); + + + public void addNewNBT(ItemStack itemStack) { + + } + + public net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) { + return CraftItemStack.asNMSCopy(itemStack); + } + + @NonNull + public NBTTagCompound getNBTCopy(ItemStack itemStack) { + net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + return nmsItemStack.save(new NBTTagCompound()); + } + + public void addFloatNBT(ItemStack itemStack, String key, float value) { + //NBT Copied off Item + net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack); + NBTTagCompound freshNBTCopy = nmsIS.save(new NBTTagCompound()); + + //New Float NBT Value + NBTTagCompound updatedNBT = new NBTTagCompound(); + updatedNBT.setFloat(key, value); + + //Merge + freshNBTCopy.a(updatedNBT); + + //Invoke load() time + applyNBT(nmsIS, updatedNBT); + } + + + public net.minecraft.server.v1_14_R1.ItemStack applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) { try { Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack"); @@ -72,26 +96,10 @@ public class NBTManager { e.printStackTrace(); } -// nmsItemStack.save(nbtTagCompound); -// itemStack.setItemMeta(nmsItemStack..getItemMeta()); - return itemStack; + return nmsItemStack; } - public static net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) { - return CraftItemStack.asNMSCopy(itemStack); - } - - @Nullable - public static NBTTagCompound getNBT(ItemStack itemStack) { - net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); - return nmsItemStack.getTag(); - } - - public static void addFloatNBT(NBTTagCompound nbtTagCompound, String key, float value) { - nbtTagCompound.setFloat(key, value); - } - - public static NBTBase constructNBT(String nbtString) { + public NBTBase constructNBT(String nbtString) { try { return CraftNBTTagConfigSerializer.deserialize(nbtString); } catch (Exception e) { @@ -101,7 +109,7 @@ public class NBTManager { } } - public static void printNBT(NBTTagCompound nbtTagCompound, Player player) { + public void printNBT(NBTTagCompound nbtTagCompound, Player player) { for(String key : nbtTagCompound.getKeys()) { player.sendMessage(""); player.sendMessage("NBT Key: "+key); @@ -109,7 +117,7 @@ public class NBTManager { } } - public static boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) { + public boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) { if(nbt instanceof NBTList) { } else { From ec1fdea40d4e15c5aa032f56748d5f57f7d26d43 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 16:23:59 -0700 Subject: [PATCH 05/20] Progress??? --- .../java/com/gmail/nossr50/util/nbt/NBTManager.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index e3830438f..e3c26c054 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -37,22 +37,20 @@ public class NBTManager { NBTTagCompound nbtTagCompound = getNBTCopy(itemStack); player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size()); - printNBT(nbtTagCompound, player); + printNBT(itemStack, player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to add NBT key named - Herp"); addFloatNBT(itemStack, "herp", 13.37F); player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size()); - printNBT(nbtTagCompound, player); + printNBT(itemStack, player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to save NBT data..."); player.updateInventory(); } - - public void addNewNBT(ItemStack itemStack) { } @@ -109,11 +107,12 @@ public class NBTManager { } } - public void printNBT(NBTTagCompound nbtTagCompound, Player player) { - for(String key : nbtTagCompound.getKeys()) { + public void printNBT(ItemStack itemStack, Player player) { + NBTTagCompound tagCompoundCopy = getNBTCopy(itemStack); + for(String key : tagCompoundCopy.getKeys()) { player.sendMessage(""); player.sendMessage("NBT Key: "+key); - player.sendMessage("NBT Value: " + nbtTagCompound.get(key).asString()); + player.sendMessage("NBT Value: " + tagCompoundCopy.get(key).asString()); } } From 7f6bbadc1ca4e32d0630088038e511c541cff32b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 16:28:46 -0700 Subject: [PATCH 06/20] Less error prone Kappa --- .../com/gmail/nossr50/util/nbt/NBTManager.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index e3c26c054..fe6e2129e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -32,29 +32,26 @@ public class NBTManager { public void debugNBTInMainHandItem(Player player) { player.sendMessage("Starting NBT Debug Dump..."); + ItemStack itemStack = player.getInventory().getItemInMainHand(); player.sendMessage("Checking NBT for "+itemStack.toString()); - NBTTagCompound nbtTagCompound = getNBTCopy(itemStack); - player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size()); - printNBT(itemStack, player); + player.sendMessage("Total NBT Entries: "+getNBTCopy(player.getInventory().getItemInMainHand()).getKeys().size()); + printNBT(player.getInventory().getItemInMainHand(), player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to add NBT key named - Herp"); - addFloatNBT(itemStack, "herp", 13.37F); + addFloatNBT(player.getInventory().getItemInMainHand(), "herp", 13.37F); + player.updateInventory(); - player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size()); - printNBT(itemStack, player); + player.sendMessage("(After HERP) Total NBT Entries: "+getNBTCopy(player.getInventory().getItemInMainHand()).getKeys().size()); + printNBT(player.getInventory().getItemInMainHand(), player); player.sendMessage("-- END OF NBT REPORT --"); player.sendMessage("Attempting to save NBT data..."); player.updateInventory(); } - public void addNewNBT(ItemStack itemStack) { - - } - public net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) { return CraftItemStack.asNMSCopy(itemStack); } From 365938f35123db69341ab20fbadc1ad2c1cc2690 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 16:33:31 -0700 Subject: [PATCH 07/20] ItemMeta needed? --- .../main/java/com/gmail/nossr50/util/nbt/NBTManager.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index fe6e2129e..8c5ef16d8 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -76,10 +76,14 @@ public class NBTManager { //Invoke load() time applyNBT(nmsIS, updatedNBT); + + //Apply Item Meta (Not sure if needed) + CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsIS); + itemStack.setItemMeta(craftItemStack.getItemMeta()); } - public net.minecraft.server.v1_14_R1.ItemStack applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) { + public void applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) { try { Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack"); @@ -90,8 +94,6 @@ public class NBTManager { } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } - - return nmsItemStack; } public NBTBase constructNBT(String nbtString) { From 4bff07bd2bfef6aefb0af1c0b23d0df7990412a0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 1 Oct 2019 16:52:35 -0700 Subject: [PATCH 08/20] Target the tag compound --- .../gmail/nossr50/util/nbt/NBTManager.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index 8c5ef16d8..15db3265a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -59,29 +59,41 @@ public class NBTManager { @NonNull public NBTTagCompound getNBTCopy(ItemStack itemStack) { net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); - return nmsItemStack.save(new NBTTagCompound()); + NBTTagCompound freshNBTCopy = nmsItemStack.save(new NBTTagCompound()); + + if(!freshNBTCopy.hasKeyOfType("tag", 10)) { + freshNBTCopy.set("tag", new NBTTagCompound()); + } + + return freshNBTCopy; } public void addFloatNBT(ItemStack itemStack, String key, float value) { //NBT Copied off Item net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack); - NBTTagCompound freshNBTCopy = nmsIS.save(new NBTTagCompound()); + NBTTagCompound freshNBTCopy = getNBTCopy(itemStack); //New Float NBT Value NBTTagCompound updatedNBT = new NBTTagCompound(); updatedNBT.setFloat(key, value); //Merge - freshNBTCopy.a(updatedNBT); + mergeToTagCompound(freshNBTCopy, updatedNBT); //Invoke load() time - applyNBT(nmsIS, updatedNBT); + applyNBT(nmsIS, freshNBTCopy); //Apply Item Meta (Not sure if needed) CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsIS); itemStack.setItemMeta(craftItemStack.getItemMeta()); } + public void mergeToTagCompound(NBTTagCompound targetCompound, NBTTagCompound modificationCompound) { + NBTTagCompound tagCompound = (NBTTagCompound) targetCompound.get("tag"); + tagCompound.a(modificationCompound); + } + + public void applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) { From edc8701e35fa5d8c96647224282099a1746fb885 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 22 Oct 2019 16:13:53 -0700 Subject: [PATCH 09/20] Some JavaDocs --- .../gmail/nossr50/util/nbt/NBTManager.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index 15db3265a..4fb1154f7 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -30,6 +30,23 @@ public class NBTManager { // } } + /** + * Used for testing NBT stuff, will be deleted later + * @param player target player + */ + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE + //TODO: DELETE public void debugNBTInMainHandItem(Player player) { player.sendMessage("Starting NBT Debug Dump..."); @@ -52,10 +69,20 @@ public class NBTManager { player.updateInventory(); } + /** + * Gets the NMS.ItemStack Copy of a Bukkit.ItemStack + * @param itemStack target bukkit ItemStack + * @return the NMS.ItemStack "copy" of the Bukkit ItemStack + */ public net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) { return CraftItemStack.asNMSCopy(itemStack); } + /** + * Copies the NBT off an ItemStack and adds a tag compound if it doesn't exist + * @param itemStack target ItemStack + * @return the NBT copy of an ItemStack + */ @NonNull public NBTTagCompound getNBTCopy(ItemStack itemStack) { net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); @@ -68,6 +95,12 @@ public class NBTManager { return freshNBTCopy; } + /** + * Adds a Float Value to an ItemStack's NBT + * @param itemStack target ItemStack + * @param key the key for the new NBT float kv pair + * @param value the value of the new NBT float kv pair + */ public void addFloatNBT(ItemStack itemStack, String key, float value) { //NBT Copied off Item net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack); @@ -88,13 +121,21 @@ public class NBTManager { itemStack.setItemMeta(craftItemStack.getItemMeta()); } + /** + * Merges the modification compound into the target compound's tag NBT node + * @param targetCompound target NBT to merge into + * @param modificationCompound data to merge + */ public void mergeToTagCompound(NBTTagCompound targetCompound, NBTTagCompound modificationCompound) { NBTTagCompound tagCompound = (NBTTagCompound) targetCompound.get("tag"); tagCompound.a(modificationCompound); } - - + /** + * Applies NBT to an NMS.ItemStack + * @param nmsItemStack target NMS.ItemStack + * @param nbtTagCompound the new NBT data for the NMS.ItemStack + */ public void applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) { try { @@ -118,6 +159,11 @@ public class NBTManager { } } + /** + * Prints all the NBT KV pairs on an ItemStack + * @param itemStack target ItemStack + * @param player target player to send the message to + */ public void printNBT(ItemStack itemStack, Player player) { NBTTagCompound tagCompoundCopy = getNBTCopy(itemStack); for(String key : tagCompoundCopy.getKeys()) { From 2a606b1ed1dc04e140a5ae78a2235a350c9a1f60 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 28 Oct 2019 19:47:38 -0700 Subject: [PATCH 10/20] Our own basic NBT types --- .../com/gmail/nossr50/core/nbt/NBTBase.java | 11 ++++++ .../com/gmail/nossr50/core/nbt/NBTByte.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTByteArray.java | 32 +++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTDouble.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTFloat.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTIntArray.java | 32 +++++++++++++++++ .../gmail/nossr50/core/nbt/NBTInteger.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTList.java | 35 +++++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTLong.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTLongArray.java | 32 +++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTShort.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTString.java | 28 +++++++++++++++ .../nossr50/core/nbt/NBTTagCompound.java | 18 ++++++++++ .../com/gmail/nossr50/core/nbt/NBTType.java | 22 ++++++++++++ 14 files changed, 378 insertions(+) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java new file mode 100644 index 000000000..620100b85 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java @@ -0,0 +1,11 @@ +package com.gmail.nossr50.core.nbt; + +public interface NBTBase { + + /** + * Get the NBTType for this NBTBase + * @return this NBTType + */ + NBTType getNBTType(); + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java new file mode 100644 index 000000000..ca1635243 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTByte implements NBTBase { + + private String key; + private Byte value; + + @Override + public NBTType getNBTType() { + return NBTType.BYTE; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Byte getValue() { + return value; + } + + public void setValue(Byte value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java new file mode 100644 index 000000000..312837442 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTByteArray implements NBTBase { + + private String key; + private byte[] values; + + @Override + public NBTType getNBTType() { + return NBTType.BYTE_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public byte[] getValues() { + return values; + } + + public void setValues(byte[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java new file mode 100644 index 000000000..4b3ed06be --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTDouble implements NBTBase { + + private String key; + private double value; + + @Override + public NBTType getNBTType() { + return NBTType.DOUBLE; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java new file mode 100644 index 000000000..5bbb9a36f --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTFloat implements NBTBase { + + private String key; + private float value; + + @Override + public NBTType getNBTType() { + return NBTType.FLOAT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java new file mode 100644 index 000000000..fce90d9c8 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTIntArray implements NBTBase { + + private String key; + private int[] values; + + @Override + public NBTType getNBTType() { + return NBTType.INT_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public int[] getValues() { + return values; + } + + public void setValues(int[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java new file mode 100644 index 000000000..2591bba3b --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTInteger implements NBTBase { + + private String key; + private int value; + + @Override + public NBTType getNBTType() { + return NBTType.INT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java new file mode 100644 index 000000000..f98653560 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java @@ -0,0 +1,35 @@ +package com.gmail.nossr50.core.nbt; + +import java.util.List; + +public class NBTList implements NBTBase { + + private int length; + private String key; + private List values; + + @Override + public NBTType getNBTType() { + return NBTType.LIST; + } + + public int getLength() { + return length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public List getValues() { + return values; + } + + public void setValues(List values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java new file mode 100644 index 000000000..630f748fa --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTLong implements NBTBase { + + public String key; + public long value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } + + @Override + public NBTType getNBTType() { + return NBTType.LONG; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java new file mode 100644 index 000000000..feb7aee26 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTLongArray implements NBTBase { + + private String key; + private long[] values; + + @Override + public NBTType getNBTType() { + return NBTType.LONG_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public long[] getValues() { + return values; + } + + public void setValues(long[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java new file mode 100644 index 000000000..db64f624d --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTShort implements NBTBase { + + private String key; + private short value; + + @Override + public NBTType getNBTType() { + return NBTType.SHORT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public short getValue() { + return value; + } + + public void setValue(short value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java new file mode 100644 index 000000000..123e82665 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTString implements NBTBase { + + private String key; + private String value; + + @Override + public NBTType getNBTType() { + return NBTType.STRING; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java new file mode 100644 index 000000000..26dbbc7d4 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java @@ -0,0 +1,18 @@ +package com.gmail.nossr50.core.nbt; + +import java.util.Map; + +public class NBTTagCompound implements NBTBase { + + private Map tagMap; + + @Override + public NBTType getNBTType() { + return NBTType.COMPOUND; + } + + public NBTBase getTag(String key) { + return tagMap.get(key); + } + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java new file mode 100644 index 000000000..40d162dbf --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java @@ -0,0 +1,22 @@ +package com.gmail.nossr50.core.nbt; + +/** + * Represents the NBT Type + * Based on NBT Structure in 1.14.4 + */ +public enum NBTType { + ////String[] a = new String[]{"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]", "LONG[]"}; + END, + BYTE, + SHORT, + INT, + LONG, + FLOAT, + DOUBLE, + BYTE_ARRAY, + STRING, + LIST, + COMPOUND, + INT_ARRAY, + LONG_ARRAY +} From bfcc1678627b43997d5451c9b65e4fa5af1241e9 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 29 Oct 2019 12:23:39 -0700 Subject: [PATCH 11/20] Flesh out NBT types --- .../com/gmail/nossr50/core/nbt/NBTByte.java | 1 + .../com/gmail/nossr50/core/nbt/NBTList.java | 3 +- .../nossr50/core/nbt/NBTTagCompound.java | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java index ca1635243..b01a15f21 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -25,4 +25,5 @@ public class NBTByte implements NBTBase { public void setValue(Byte value) { this.value = value; } + } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java index f98653560..45b2bc8e6 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java @@ -4,7 +4,6 @@ import java.util.List; public class NBTList implements NBTBase { - private int length; private String key; private List values; @@ -14,7 +13,7 @@ public class NBTList implements NBTBase { } public int getLength() { - return length; + return values.size(); } public String getKey() { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java index 26dbbc7d4..d5ca3c542 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java @@ -1,11 +1,19 @@ package com.gmail.nossr50.core.nbt; +import java.util.Collection; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; public class NBTTagCompound implements NBTBase { + private String key; private Map tagMap; + public NBTTagCompound(String key) { + tagMap = new LinkedHashMap<>(); + } + @Override public NBTType getNBTType() { return NBTType.COMPOUND; @@ -15,4 +23,32 @@ public class NBTTagCompound implements NBTBase { return tagMap.get(key); } + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public void addNBT(String tagKey, NBTBase nbt) { + tagMap.put(tagKey, nbt); + } + + public Collection getMapValues() { + return tagMap.values(); + } + + public Set getMapKeys() { + return tagMap.keySet(); + } + + public int getMapSize() { + return tagMap.size(); + } + + public void removeEntry(String tagKey) { + tagMap.remove(tagKey); + } } + From bf94073935877287587b5bf7ff2094c925aaed57 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 29 Oct 2019 19:00:16 -0700 Subject: [PATCH 12/20] Work on NBT adapters --- .../nossr50/core/adapters/NBTAdapter.java | 7 ++ .../adapters/NMS_114/BukkitNBTAdapter.java | 93 +++++++++++++++++++ .../NMS_114/BukkitPlatformAdapter.java | 17 ++++ .../core/adapters/PlatformAdapter.java | 15 +++ .../com/gmail/nossr50/core/nbt/NBTByte.java | 4 + .../{NBTTagCompound.java => NBTCompound.java} | 4 +- .../com/gmail/nossr50/core/nbt/NBTEnd.java | 8 ++ .../com/gmail/nossr50/core/nbt/NBTLong.java | 4 +- .../gmail/nossr50/util/nbt/NBTFactory.java | 69 ++++++++++++++ 9 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java rename mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/{NBTTagCompound.java => NBTCompound.java} (91%) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTEnd.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java new file mode 100644 index 000000000..8a6ee639f --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java @@ -0,0 +1,7 @@ +package com.gmail.nossr50.core.adapters; + +import com.gmail.nossr50.core.nbt.NBTBase; + +public interface NBTAdapter { + Object asNative(NBTBase nbtBase); +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java new file mode 100644 index 000000000..79cd5b4b9 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java @@ -0,0 +1,93 @@ +package com.gmail.nossr50.core.adapters.NMS_114; + +import com.gmail.nossr50.core.adapters.NBTAdapter; +import com.gmail.nossr50.core.nbt.*; +import com.gmail.nossr50.core.nbt.NBTBase; +import com.gmail.nossr50.core.nbt.NBTList; +import com.gmail.nossr50.core.nbt.NBTCompound; +import net.minecraft.server.v1_14_R1.*; + +public class BukkitNBTAdapter implements NBTAdapter { + + @Override + public Object asNative(NBTBase nbtBase) { + switch(nbtBase.getNBTType()) { + case END: + return new NBTTagEnd(); + case BYTE: + return asNativeNBTByte((NBTByte) nbtBase); + case SHORT: + return asNativeNBTShort((NBTShort) nbtBase); + case INT: + return asNativeNBTInt((NBTInteger) nbtBase); + case LONG: + return asNativeNBTLong((NBTLong) nbtBase); + case FLOAT: + return asNativeNBTFloat((NBTFloat) nbtBase); + case DOUBLE: + return asNativeNBTDouble((NBTDouble) nbtBase); + case BYTE_ARRAY: + return asNativeNBTByteArray((NBTByteArray) nbtBase); + case STRING: + return asNativeNBTString((NBTString) nbtBase); + case LIST: + return asNativeNBTList((NBTList) nbtBase); + case COMPOUND: + return ; + case INT_ARRAY: + break; + case LONG_ARRAY: + break; + } + + return null; + } + + /** + * Create a NBTTagByte (NMS Type) from our NBTByte representation + * @param nbtByte target NBTByte + * @return NBTTagByte copy of our NBTByte representation + */ + private NBTTagByte asNativeNBTByte(NBTByte nbtByte) { + return new NBTTagByte(nbtByte.getValue()); + } + + private NBTTagShort asNativeNBTShort(NBTShort nbtShort) { + return new NBTTagShort(nbtShort.getValue()); + } + + private NBTTagInt asNativeNBTInt(NBTInteger nbtInteger) { + return new NBTTagInt(nbtInteger.getValue()); + } + + private NBTTagLong asNativeNBTLong(NBTLong nbtLong) { + return new NBTTagLong(nbtLong.getValue()); + } + + private NBTTagFloat asNativeNBTFloat(NBTFloat nbtFloat) { + return new NBTTagFloat(nbtFloat.getValue()); + } + + private NBTTagDouble asNativeNBTDouble(NBTDouble nbtDouble) { + return new NBTTagDouble(nbtDouble.getValue()); + } + + private NBTTagByteArray asNativeNBTByteArray(NBTByteArray nbtByteArray) { + return new NBTTagByteArray(nbtByteArray.getValues()); + } + + private NBTTagString asNativeNBTString(NBTString nbtString) { + return new NBTTagString(nbtString.getValue()); + } + + private NBTTagList asNativeNBTList(NBTList nbtList) { + NBTTagList nbtTagList = new NBTTagList(); + nbtList.setValues(nbtList.getValues()); + return nbtTagList; + } + + private NBTTagCompound asNativeNBTCompound(NBTCompound nbtCompound) { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + nbtCompound + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java new file mode 100644 index 000000000..c97df31bf --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java @@ -0,0 +1,17 @@ +package com.gmail.nossr50.core.adapters.NMS_114; + +import com.gmail.nossr50.core.adapters.NBTAdapter; +import com.gmail.nossr50.core.adapters.PlatformAdapter; +import com.gmail.nossr50.core.nbt.NBTBase; +import com.gmail.nossr50.core.nbt.NBTByte; +import net.minecraft.server.v1_14_R1.NBTTagByte; + +public class BukkitPlatformAdapter extends PlatformAdapter { + + public BukkitPlatformAdapter() { + super(new BukkitNBTAdapter()); + } + + + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java new file mode 100644 index 000000000..3a6853e45 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java @@ -0,0 +1,15 @@ +package com.gmail.nossr50.core.adapters; + +public abstract class PlatformAdapter { + + private NBTAdapter nbtAdapter; //nbt + + public PlatformAdapter(NBTAdapter nbtAdapter) { + this.nbtAdapter = nbtAdapter; + } + + public NBTAdapter getNbtAdapter() { + return nbtAdapter; + } + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java index b01a15f21..93a3fab17 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -5,6 +5,10 @@ public class NBTByte implements NBTBase { private String key; private Byte value; + public NBTByte(Byte value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.BYTE; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java similarity index 91% rename from mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java rename to mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java index d5ca3c542..70d6d544d 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java @@ -5,12 +5,12 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -public class NBTTagCompound implements NBTBase { +public class NBTCompound implements NBTBase { private String key; private Map tagMap; - public NBTTagCompound(String key) { + public NBTCompound(String key) { tagMap = new LinkedHashMap<>(); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTEnd.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTEnd.java new file mode 100644 index 000000000..71bf1d7ef --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTEnd.java @@ -0,0 +1,8 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTEnd implements NBTBase { + @Override + public NBTType getNBTType() { + return NBTType.END; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java index 630f748fa..20e6f50ea 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java @@ -2,8 +2,8 @@ package com.gmail.nossr50.core.nbt; public class NBTLong implements NBTBase { - public String key; - public long value; + private String key; + private long value; public String getKey() { return key; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java new file mode 100644 index 000000000..35529853f --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java @@ -0,0 +1,69 @@ +package com.gmail.nossr50.util.nbt; + +import com.gmail.nossr50.core.nbt.NBTByte; +import com.gmail.nossr50.core.nbt.NBTCompound; +import net.minecraft.server.v1_14_R1.NBTTagByte; + +public class NBTFactory { + /** + * Converts NMS NBT types into our own NBT type representation + * @param nmsNBT target NMS Compound + * @return NMS Representation of our NBT + */ + public NBTCompound asNBT(net.minecraft.server.v1_14_R1.NBTTagCompound nmsNBT) { + NBTCompound nbtCompound = new NBTCompound(""); + + //Traverse the NMS Map + for(String key : nmsNBT.getKeys()) { + + } + } + + /** + * Convert our NBT type into the NMS NBT Type equivalent + * @param nbtCompound target nbt compound + * @return NMS NBT copy of our NBT type + */ + public net.minecraft.server.v1_14_R1.NBTTagCompound asNMSCopy(NBTCompound nbtCompound) { + + } + + /** + * Create a new NMS NBT tag compound with only 1 tag compound named "tag" + * @return new NMS NBT tag compound + */ + private net.minecraft.server.v1_14_R1.NBTTagCompound makeNewNMSNBT() { + net.minecraft.server.v1_14_R1.NBTTagCompound nbtTagCompound = new net.minecraft.server.v1_14_R1.NBTTagCompound(); + + //Add the 'tag' compound where arbitrary data persists + nbtTagCompound.set("tag", new net.minecraft.server.v1_14_R1.NBTTagCompound()); + return nbtTagCompound; + } + + private NBTCompound deepCopy(NBTCompound target, String key, net.minecraft.server.v1_14_R1.NBTBase nbtBase) { + switch (nbtBase.getTypeId()) { + case 0: + return new NBTCompound(); + } + } + + /** + * Create a NBTByte representation of NBTTagByte (NMS Type) + * @param nmsNBTByte target NMS NBTTagByte + * @return NBTByte representation of the targeted NMS nbt-type + */ + private NBTByte asNBTByte(NBTTagByte nmsNBTByte) { + NBTByte nbtByte = new NBTByte(nmsNBTByte.asByte()); + return nbtByte; + } + + /** + * Create a NBTTagByte (NMS Type) from our NBTByte representation + * @param nbtByte target NBTByte + * @return NBTTagByte copy of our NBTByte representation + */ + private NBTTagByte asNBTTagByte(NBTByte nbtByte) { + NBTTagByte nbtTagByte = new NBTTagByte(nbtByte.getValue()); + return nbtTagByte; + } +} From fdb900ec5dd4b549ed458d85b46c884ace739f46 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 30 Oct 2019 14:38:02 -0700 Subject: [PATCH 13/20] PlatformManager to manage the platform adapters --- .../gmail/nossr50/core/PlatformManager.java | 34 +++++++++++++++++++ .../adapters/NMS_114/BukkitNBTAdapter.java | 3 +- .../NMS_114/BukkitPlatformAdapter.java | 6 ---- .../main/java/com/gmail/nossr50/mcMMO.java | 9 +++++ 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/PlatformManager.java diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/PlatformManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/PlatformManager.java new file mode 100644 index 000000000..52577f163 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/PlatformManager.java @@ -0,0 +1,34 @@ +package com.gmail.nossr50.core; + +import com.gmail.nossr50.core.adapters.NMS_114.BukkitPlatformAdapter; +import com.gmail.nossr50.core.adapters.PlatformAdapter; +import com.gmail.nossr50.mcMMO; + +public class PlatformManager { + private PlatformAdapter platformAdapter; + private mcMMO pluginRef; + + public PlatformManager(mcMMO pluginRef) { + this.pluginRef = pluginRef; + initAdapters(); + } + + /** + * Initialize the adapters based on the current platform + */ + private void initAdapters() { + pluginRef.getLogger().info("Initializing platform adapters..."); + //Determine which platform we are on and load the correct adapter + //For now this will be hardcoded for testing purposes + platformAdapter = new BukkitPlatformAdapter(); + } + + /** + * Get the current platform adapter implementation + * @return the current platform adapter + */ + public PlatformAdapter getPlatformAdapter() { + return platformAdapter; + } + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java index 79cd5b4b9..5b8791f95 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java @@ -1,10 +1,9 @@ package com.gmail.nossr50.core.adapters.NMS_114; import com.gmail.nossr50.core.adapters.NBTAdapter; -import com.gmail.nossr50.core.nbt.*; import com.gmail.nossr50.core.nbt.NBTBase; import com.gmail.nossr50.core.nbt.NBTList; -import com.gmail.nossr50.core.nbt.NBTCompound; +import com.gmail.nossr50.core.nbt.*; import net.minecraft.server.v1_14_R1.*; public class BukkitNBTAdapter implements NBTAdapter { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java index c97df31bf..5dee0d806 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitPlatformAdapter.java @@ -1,10 +1,6 @@ package com.gmail.nossr50.core.adapters.NMS_114; -import com.gmail.nossr50.core.adapters.NBTAdapter; import com.gmail.nossr50.core.adapters.PlatformAdapter; -import com.gmail.nossr50.core.nbt.NBTBase; -import com.gmail.nossr50.core.nbt.NBTByte; -import net.minecraft.server.v1_14_R1.NBTTagByte; public class BukkitPlatformAdapter extends PlatformAdapter { @@ -12,6 +8,4 @@ public class BukkitPlatformAdapter extends PlatformAdapter { super(new BukkitNBTAdapter()); } - - } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java index f6d49b4f8..d25edc1a0 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -11,6 +11,7 @@ import com.gmail.nossr50.config.scoreboard.ConfigScoreboard; import com.gmail.nossr50.core.DynamicSettingsManager; import com.gmail.nossr50.core.MaterialMapStore; import com.gmail.nossr50.core.MetadataConstants; +import com.gmail.nossr50.core.PlatformManager; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll; @@ -86,6 +87,7 @@ public class mcMMO extends JavaPlugin { private ScoreboardManager scoreboardManager; private SoundManager soundManager; private HardcoreManager hardcoreManager; + private PlatformManager platformManager; /* Not-Managers but my naming scheme sucks */ private DatabaseManagerFactory databaseManagerFactory; @@ -132,6 +134,9 @@ public class mcMMO extends JavaPlugin { try { getLogger().setFilter(new LogFilter(this)); + //Init PlatformManager + platformManager = new PlatformManager(this); + //TODO: Disgusting... MetadataConstants.metadataValue = new FixedMetadataValue(this, true); @@ -862,4 +867,8 @@ public class mcMMO extends JavaPlugin { public NBTManager getNbtManager() { return nbtManager; } + + public PlatformManager getPlatformManager() { + return platformManager; + } } From 9911c406f8c56ba24aec5944f2b7ce16f827bf41 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 30 Oct 2019 14:56:30 -0700 Subject: [PATCH 14/20] Refactor some Type names and javadocs --- .../nossr50/core/adapters/NBTAdapter.java | 6 ++ .../adapters/NMS_114/BukkitNBTAdapter.java | 73 +++++++++++++++++-- .../core/adapters/PlatformAdapter.java | 4 + .../core/nbt/{NBTInteger.java => NBTInt.java} | 2 +- 4 files changed, 79 insertions(+), 6 deletions(-) rename mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/{NBTInteger.java => NBTInt.java} (90%) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java index 8a6ee639f..7013f0d3b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java @@ -3,5 +3,11 @@ package com.gmail.nossr50.core.adapters; import com.gmail.nossr50.core.nbt.NBTBase; public interface NBTAdapter { + + /** + * Transform our NBT type representation to its implementation on the target platform + * @param nbtBase target NBT type representation + * @return platform specific implementation of our NBT Type + */ Object asNative(NBTBase nbtBase); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java index 5b8791f95..8930c66ed 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java @@ -18,7 +18,7 @@ public class BukkitNBTAdapter implements NBTAdapter { case SHORT: return asNativeNBTShort((NBTShort) nbtBase); case INT: - return asNativeNBTInt((NBTInteger) nbtBase); + return asNativeNBTInt((NBTInt) nbtBase); case LONG: return asNativeNBTLong((NBTLong) nbtBase); case FLOAT: @@ -34,9 +34,9 @@ public class BukkitNBTAdapter implements NBTAdapter { case COMPOUND: return ; case INT_ARRAY: - break; + return asNativeNBTIntArray((NBTIntArray) nbtBase); case LONG_ARRAY: - break; + return asNativeNBTLongArray((NBTLongArray) nbtBase); } return null; @@ -51,42 +51,105 @@ public class BukkitNBTAdapter implements NBTAdapter { return new NBTTagByte(nbtByte.getValue()); } + /** + * Create a NBTTagShort (NMS Type) from our NBTShort representation + * @param nbtShort target NBTShort + * @return NBTTagShort copy of our NBTShort representation + */ private NBTTagShort asNativeNBTShort(NBTShort nbtShort) { return new NBTTagShort(nbtShort.getValue()); } - private NBTTagInt asNativeNBTInt(NBTInteger nbtInteger) { - return new NBTTagInt(nbtInteger.getValue()); + /** + * Create a NBTTagInt (NMS Type) from our NBTInt representation + * @param nbtInt target NBTInt + * @return NBTTagInt copy of our NBTInt representation + */ + private NBTTagInt asNativeNBTInt(NBTInt nbtInt) { + return new NBTTagInt(nbtInt.getValue()); } + /** + * Create a NBTTagLong (NMS Type) from our NBTLong representation + * @param nbtLong target NBTLong + * @return NBTTagLong copy of our NBTLong representation + */ private NBTTagLong asNativeNBTLong(NBTLong nbtLong) { return new NBTTagLong(nbtLong.getValue()); } + /** + * Create a NBTTagFloat (NMS Type) from our NBTFloat representation + * @param nbtFloat target NBTFloat + * @return NBTTagFloat copy of our NBTFloat representation + */ private NBTTagFloat asNativeNBTFloat(NBTFloat nbtFloat) { return new NBTTagFloat(nbtFloat.getValue()); } + /** + * Create a NBTTagDouble (NMS Type) from our NBTDouble representation + * @param nbtDouble target NBTDouble + * @return NBTTagDouble copy of our NBTDouble representation + */ private NBTTagDouble asNativeNBTDouble(NBTDouble nbtDouble) { return new NBTTagDouble(nbtDouble.getValue()); } + /** + * Create a NBTTagByteArray (NMS Type) from our NBTByteArray representation + * @param nbtByteArray target NBTByteArray + * @return NBTTagByteArray copy of our NBTByteArray representation + */ private NBTTagByteArray asNativeNBTByteArray(NBTByteArray nbtByteArray) { return new NBTTagByteArray(nbtByteArray.getValues()); } + /** + * Create a NBTTagString (NMS Type) from our NBTString representation + * @param nbtString target NBTString + * @return NBTTagString copy of our NBTString representation + */ private NBTTagString asNativeNBTString(NBTString nbtString) { return new NBTTagString(nbtString.getValue()); } + /** + * Create a NBTTagList (NMS Type) from our NBTList representation + * @param nbtList target NBTList + * @return NBTTagList copy of our NBTList representation + */ private NBTTagList asNativeNBTList(NBTList nbtList) { NBTTagList nbtTagList = new NBTTagList(); nbtList.setValues(nbtList.getValues()); return nbtTagList; } + /** + * Create a NBTTagCompound (NMS Type) from our NBTCompound representation + * @param nbtCompound target NBTCompound + * @return NBTTagCompound copy of our NBTCompound representation + */ private NBTTagCompound asNativeNBTCompound(NBTCompound nbtCompound) { NBTTagCompound nbtTagCompound = new NBTTagCompound(); nbtCompound } + + /** + * Create a NBTTagIntArray (NMS Type) from our NBTIntArray representation + * @param nbtIntArray target NBTIntArray + * @return NBTTagIntArray copy of our NBTIntArray representation + */ + private NBTTagIntArray asNativeNBTIntArray(NBTIntArray nbtIntArray) { + return new NBTTagIntArray(nbtIntArray.getValues()); + } + + /** + * Create a NBTTagLongArray (NMS Type) from our NBTLongArray representation + * @param nbtLongArray target NBTLongArray + * @return NBTTagLongArray copy of our NBTLongArray representation + */ + private NBTTagLongArray asNativeNBTLongArray(NBTLongArray nbtLongArray) { + return new NBTTagLongArray(nbtLongArray.getValues()); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java index 3a6853e45..0d49ac52e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java @@ -8,6 +8,10 @@ public abstract class PlatformAdapter { this.nbtAdapter = nbtAdapter; } + /** + * Get the NBT Adapter for this platform + * @return the platform's NBT adapter + */ public NBTAdapter getNbtAdapter() { return nbtAdapter; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java similarity index 90% rename from mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java rename to mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java index 2591bba3b..a13ddca1a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.nbt; -public class NBTInteger implements NBTBase { +public class NBTInt implements NBTBase { private String key; private int value; From 25a9c75a5a127ed233d3f6a85ee9cedee2a300ae Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 31 Oct 2019 20:15:36 -0700 Subject: [PATCH 15/20] Flesh out NBT types --- .../com/gmail/nossr50/core/nbt/NBTByte.java | 38 +++++++++++------ .../gmail/nossr50/core/nbt/NBTByteArray.java | 37 ++++++++++++---- .../gmail/nossr50/core/nbt/NBTCompound.java | 39 ++++++++++------- .../com/gmail/nossr50/core/nbt/NBTDouble.java | 35 ++++++++++++---- .../com/gmail/nossr50/core/nbt/NBTFloat.java | 35 ++++++++++++---- .../com/gmail/nossr50/core/nbt/NBTInt.java | 35 ++++++++++++---- .../gmail/nossr50/core/nbt/NBTIntArray.java | 37 ++++++++++++---- .../com/gmail/nossr50/core/nbt/NBTList.java | 39 ++++++++++++----- .../com/gmail/nossr50/core/nbt/NBTLong.java | 31 ++++++++++---- .../gmail/nossr50/core/nbt/NBTLongArray.java | 35 ++++++++++++---- .../com/gmail/nossr50/core/nbt/NBTShort.java | 35 ++++++++++++---- .../com/gmail/nossr50/core/nbt/NBTString.java | 42 ++++++++++++++----- 12 files changed, 321 insertions(+), 117 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java index 93a3fab17..d484da24d 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -1,11 +1,12 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTByte implements NBTBase { - private String key; - private Byte value; + private byte value; - public NBTByte(Byte value) { + public NBTByte(byte value) { this.value = value; } @@ -14,20 +15,31 @@ public class NBTByte implements NBTBase { return NBTType.BYTE; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public Byte getValue() { + public byte getValue() { return value; } - public void setValue(Byte value) { + public void setValue(byte value) { this.value = value; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTByte nbtByte = (NBTByte) o; + return value == nbtByte.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } + + @Override + public String toString() { + return "NBTByte{" + + "value=" + value + + '}'; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java index 312837442..31a733a73 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java @@ -1,10 +1,17 @@ package com.gmail.nossr50.core.nbt; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.Arrays; + public class NBTByteArray implements NBTBase { - private String key; private byte[] values; + public NBTByteArray(byte[] values) { + this.values = values; + } + @Override public NBTType getNBTType() { return NBTType.BYTE_ARRAY; @@ -14,14 +21,6 @@ public class NBTByteArray implements NBTBase { return values.length; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public byte[] getValues() { return values; } @@ -29,4 +28,24 @@ public class NBTByteArray implements NBTBase { public void setValues(byte[] values) { this.values = values; } + + @Override + public String toString() { + return "NBTByteArray{" + + "values=" + Arrays.toString(values) + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTByteArray that = (NBTByteArray) o; + return Arrays.equals(values, that.values); + } + + @Override + public int hashCode() { + return Arrays.hashCode(values); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java index 70d6d544d..a34150975 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java @@ -1,16 +1,15 @@ package com.gmail.nossr50.core.nbt; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.*; public class NBTCompound implements NBTBase { - private String key; + @NonNull private Map tagMap; - public NBTCompound(String key) { + public NBTCompound() { tagMap = new LinkedHashMap<>(); } @@ -23,14 +22,6 @@ public class NBTCompound implements NBTBase { return tagMap.get(key); } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public void addNBT(String tagKey, NBTBase nbt) { tagMap.put(tagKey, nbt); } @@ -50,5 +41,25 @@ public class NBTCompound implements NBTBase { public void removeEntry(String tagKey) { tagMap.remove(tagKey); } + + @Override + public String toString() { + return "NBTCompound{" + + "tagMap=" + tagMap + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTCompound that = (NBTCompound) o; + return tagMap.equals(that.tagMap); + } + + @Override + public int hashCode() { + return Objects.hash(tagMap); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java index 4b3ed06be..979ba526a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java @@ -1,23 +1,20 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTDouble implements NBTBase { - private String key; private double value; + public NBTDouble(double value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.DOUBLE; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public double getValue() { return value; } @@ -25,4 +22,24 @@ public class NBTDouble implements NBTBase { public void setValue(double value) { this.value = value; } + + @Override + public String toString() { + return "NBTDouble{" + + "value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTDouble nbtDouble = (NBTDouble) o; + return Double.compare(nbtDouble.value, value) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java index 5bbb9a36f..98a401da5 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java @@ -1,23 +1,20 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTFloat implements NBTBase { - private String key; private float value; + public NBTFloat(float value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.FLOAT; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public float getValue() { return value; } @@ -25,4 +22,24 @@ public class NBTFloat implements NBTBase { public void setValue(float value) { this.value = value; } + + @Override + public String toString() { + return "NBTFloat{" + + "value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTFloat nbtFloat = (NBTFloat) o; + return Float.compare(nbtFloat.value, value) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java index a13ddca1a..85f87a9fa 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java @@ -1,23 +1,20 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTInt implements NBTBase { - private String key; private int value; + public NBTInt(int value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.INT; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public int getValue() { return value; } @@ -25,4 +22,24 @@ public class NBTInt implements NBTBase { public void setValue(int value) { this.value = value; } + + @Override + public String toString() { + return "NBTInt{" + + "value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTInt nbtInt = (NBTInt) o; + return value == nbtInt.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java index fce90d9c8..d49d74412 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java @@ -1,10 +1,17 @@ package com.gmail.nossr50.core.nbt; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.Arrays; + public class NBTIntArray implements NBTBase { - private String key; private int[] values; + public NBTIntArray(int[] values) { + this.values = values; + } + @Override public NBTType getNBTType() { return NBTType.INT_ARRAY; @@ -14,14 +21,6 @@ public class NBTIntArray implements NBTBase { return values.length; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public int[] getValues() { return values; } @@ -29,4 +28,24 @@ public class NBTIntArray implements NBTBase { public void setValues(int[] values) { this.values = values; } + + @Override + public String toString() { + return "NBTIntArray{" + + "values=" + Arrays.toString(values) + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTIntArray that = (NBTIntArray) o; + return Arrays.equals(values, that.values); + } + + @Override + public int hashCode() { + return Arrays.hashCode(values); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java index 45b2bc8e6..706e4b68e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java @@ -1,12 +1,19 @@ package com.gmail.nossr50.core.nbt; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.List; +import java.util.Objects; public class NBTList implements NBTBase { - private String key; + @NonNull private List values; + public NBTList(@NonNull List values) { + this.values = values; + } + @Override public NBTType getNBTType() { return NBTType.LIST; @@ -16,19 +23,31 @@ public class NBTList implements NBTBase { return values.size(); } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public List getValues() { return values; } - public void setValues(List values) { + public void setValues(@NonNull List values) { this.values = values; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTList nbtList = (NBTList) o; + return values.equals(nbtList.values); + } + + @Override + public int hashCode() { + return Objects.hash(values); + } + + @Override + public String toString() { + return "NBTList{" + + "values=" + values + + '}'; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java index 20e6f50ea..35225fe47 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java @@ -1,16 +1,13 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTLong implements NBTBase { - private String key; private long value; - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; + public NBTLong(long value) { + this.value = value; } public long getValue() { @@ -25,4 +22,24 @@ public class NBTLong implements NBTBase { public NBTType getNBTType() { return NBTType.LONG; } + + @Override + public String toString() { + return "NBTLong{" + + "value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTLong nbtLong = (NBTLong) o; + return value == nbtLong.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java index feb7aee26..482ec9c6a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java @@ -1,10 +1,15 @@ package com.gmail.nossr50.core.nbt; +import java.util.Arrays; + public class NBTLongArray implements NBTBase { - private String key; private long[] values; + public NBTLongArray(long[] values) { + this.values = values; + } + @Override public NBTType getNBTType() { return NBTType.LONG_ARRAY; @@ -14,14 +19,6 @@ public class NBTLongArray implements NBTBase { return values.length; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public long[] getValues() { return values; } @@ -29,4 +26,24 @@ public class NBTLongArray implements NBTBase { public void setValues(long[] values) { this.values = values; } + + @Override + public String toString() { + return "NBTLongArray{" + + "values=" + Arrays.toString(values) + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTLongArray that = (NBTLongArray) o; + return Arrays.equals(values, that.values); + } + + @Override + public int hashCode() { + return Arrays.hashCode(values); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java index db64f624d..8b508c055 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java @@ -1,23 +1,20 @@ package com.gmail.nossr50.core.nbt; +import java.util.Objects; + public class NBTShort implements NBTBase { - private String key; private short value; + public NBTShort(short value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.SHORT; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public short getValue() { return value; } @@ -25,4 +22,24 @@ public class NBTShort implements NBTBase { public void setValue(short value) { this.value = value; } + + @Override + public String toString() { + return "NBTShort{" + + "value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTShort nbtShort = (NBTShort) o; + return value == nbtShort.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java index 123e82665..4f5a763c9 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java @@ -1,28 +1,50 @@ package com.gmail.nossr50.core.nbt; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + public class NBTString implements NBTBase { - private String key; + @NonNull private String value; + public NBTString(@NonNull String value) { + this.value = value; + } + @Override public NBTType getNBTType() { return NBTType.STRING; } - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - + @NotNull public String getValue() { return value; } - public void setValue(String value) { + public void setValue(@NotNull String value) { this.value = value; } + + @Override + public String toString() { + return "NBTString{" + + "value='" + value + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NBTString nbtString = (NBTString) o; + return value.equals(nbtString.value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } From 24ba3b1a0125c1ac2096e69322854c7f903497ef Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 7 Feb 2020 15:06:00 -0800 Subject: [PATCH 16/20] New command 'nbttools' also integrating ACF --- build.gradle.kts | 2 + mcmmo-core/build.gradle.kts | 3 ++ .../commands/admin/NBTToolsCommand.java | 15 ++++++ .../nossr50/commands/admin/PlayerDebug.java | 20 -------- .../commands/admin/PlayerDebugCommand.java | 21 ++++---- .../skills/ranks/SkillRankProperty.java | 1 - .../adapters/NMS_114/BukkitNBTAdapter.java | 7 ++- .../gmail/nossr50/core/nbt/NBTByteArray.java | 2 - .../gmail/nossr50/core/nbt/NBTIntArray.java | 2 - .../commands/CommandRegistrationManager.java | 51 +++++++++++++++---- .../gmail/nossr50/util/nbt/NBTFactory.java | 47 +++++++++-------- mcmmo-core/src/main/resources/plugin.yml | 7 +++ 12 files changed, 108 insertions(+), 70 deletions(-) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/NBTToolsCommand.java delete mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebug.java diff --git a/build.gradle.kts b/build.gradle.kts index 325e37558..f84c06abb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,8 @@ subprojects { maven("https://repo.codemc.org/repository/maven-public") maven("https://maven.sk89q.com/repo") maven("https://mvnrepository.com/artifact/org.jetbrains/annotations") + maven("https://repo.aikar.co/content/groups/aikar/") + maven("https://hub.spigotmc.org/nexus/content/groups/public/") } tasks { diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index c98b656cf..d7743b180 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -20,12 +20,14 @@ tasks { include(dependency("org.apache.tomcat:tomcat-jdbc")) include(dependency("org.apache.tomcat:tomcat-juli")) include(dependency("com.typesafe:config")) + include(dependency("co.aikar:acf-bukkit")) exclude(dependency("org.spigotmc:spigot")) } relocate("org.apache.commons.logging", "com.gmail.nossr50.commons.logging") relocate("org.apache.juli", "com.gmail.nossr50.database.tomcat.juli") relocate("org.apache.tomcat", "com.gmail.nossr50.database.tomcat") relocate("org.bstats", "com.gmail.nossr50.metrics.bstat") + relocate("co.aikar.commands", "com.gmail.nossr50.acf") } processResources { @@ -43,6 +45,7 @@ dependencies { api("org.spongepowered:configurate-core:3.7-SNAPSHOT") api("org.spongepowered:configurate-yaml:3.7-SNAPSHOT") api("org.spongepowered:configurate-hocon:3.7-SNAPSHOT") + api("co.aikar:acf-bukkit:0.5.0-SNAPSHOT") implementation("org.jetbrains:annotations:17.0.0") implementation("org.apache.maven.scm:maven-scm-provider-gitexe:1.8.1") implementation("org.bstats:bstats-bukkit:1.4") diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/NBTToolsCommand.java b/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/NBTToolsCommand.java new file mode 100644 index 000000000..82a63daab --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/NBTToolsCommand.java @@ -0,0 +1,15 @@ +package com.gmail.nossr50.commands.admin; + +import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.Dependency; +import co.aikar.commands.annotation.Description; +import com.gmail.nossr50.mcMMO; + +@Description("Read or Modify values of NBT on an item in-hand") +public class NBTToolsCommand extends BaseCommand { + + @Dependency + private mcMMO pluginRef; + + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebug.java b/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebug.java deleted file mode 100644 index 7e6849d71..000000000 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebug.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gmail.nossr50.commands.admin; - -import com.gmail.nossr50.mcMMO; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class PlayerDebug implements CommandExecutor { - - private final mcMMO pluginRef; - - public PlayerDebug(mcMMO pluginRef) { - this.pluginRef = pluginRef; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return false; - } -} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java b/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java index b48e76939..a0f885c37 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java @@ -1,29 +1,28 @@ package com.gmail.nossr50.commands.admin; +import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.Dependency; +import co.aikar.commands.annotation.Description; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.mcMMO; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class PlayerDebugCommand implements CommandExecutor { - private final mcMMO pluginRef; +@Description("Puts the player into debug mode, which helps problem solve bugs in mcMMO.") +public class PlayerDebugCommand extends BaseCommand { - public PlayerDebugCommand(mcMMO pluginRef) { - this.pluginRef = pluginRef; - } + @Dependency + private mcMMO pluginRef; - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public void onCommand(CommandSender sender) { if(sender instanceof Player) { McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer((Player) sender); mcMMOPlayer.toggleDebugMode(); //Toggle debug mode pluginRef.getNotificationManager().sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode())); - return true; } else { - return false; + //TODO: Localize + sender.sendMessage("Players only"); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/config/skills/ranks/SkillRankProperty.java b/mcmmo-core/src/main/java/com/gmail/nossr50/config/skills/ranks/SkillRankProperty.java index 96220ee83..1b7ac8398 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/config/skills/ranks/SkillRankProperty.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/config/skills/ranks/SkillRankProperty.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.config.skills.ranks; import com.gmail.nossr50.api.exceptions.MissingSkillPropertyDefinition; import com.gmail.nossr50.datatypes.skills.properties.SkillProperty; import com.gmail.nossr50.mcMMO; -import org.apache.logging.log4j.Level; import java.util.HashMap; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java index 8930c66ed..431c5a9ea 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java @@ -32,7 +32,7 @@ public class BukkitNBTAdapter implements NBTAdapter { case LIST: return asNativeNBTList((NBTList) nbtBase); case COMPOUND: - return ; + return asNativeNBTCompound((NBTCompound) nbtBase); case INT_ARRAY: return asNativeNBTIntArray((NBTIntArray) nbtBase); case LONG_ARRAY: @@ -130,9 +130,12 @@ public class BukkitNBTAdapter implements NBTAdapter { * @param nbtCompound target NBTCompound * @return NBTTagCompound copy of our NBTCompound representation */ + //TODO: Finish private NBTTagCompound asNativeNBTCompound(NBTCompound nbtCompound) { + System.out.println("FINISH asNativeNBTCompound()"); NBTTagCompound nbtTagCompound = new NBTTagCompound(); - nbtCompound + + return nbtTagCompound; } /** diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java index 31a733a73..bd6fdaa27 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.core.nbt; -import org.checkerframework.checker.nullness.qual.NonNull; - import java.util.Arrays; public class NBTByteArray implements NBTBase { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java index d49d74412..05e0bf518 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.core.nbt; -import org.checkerframework.checker.nullness.qual.NonNull; - import java.util.Arrays; public class NBTIntArray implements NBTBase { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java index 8fc2f31a7..75068f146 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.util.commands; +import co.aikar.commands.BukkitCommandManager; import com.gmail.nossr50.commands.*; +import com.gmail.nossr50.commands.admin.NBTToolsCommand; import com.gmail.nossr50.commands.admin.PlayerDebugCommand; import com.gmail.nossr50.commands.admin.ReloadLocaleCommand; import com.gmail.nossr50.commands.chat.AdminChatCommand; @@ -30,10 +32,12 @@ import java.util.Locale; public final class CommandRegistrationManager { private final mcMMO pluginRef; private String permissionsMessage; + private BukkitCommandManager bukkitCommandManager; public CommandRegistrationManager(mcMMO pluginRef) { this.pluginRef = pluginRef; permissionsMessage = pluginRef.getLocaleManager().getString("mcMMO.NoPermission"); + bukkitCommandManager = new BukkitCommandManager(pluginRef); } private void registerSkillCommands() { @@ -117,6 +121,40 @@ public final class CommandRegistrationManager { } } + /** + * Initialize ACF commands + */ + private void initACF() { + //TODO: See if needed + bukkitCommandManager.enableUnstableAPI("help"); + + + registerACFCommands(); + } + + /** + * Register ACF Commands + */ + private void registerACFCommands() { + //Register ACF Commands + registerNBTToolsCommand(); + registerMmoDebugCommand(); + } + + /** + * Register the NBT Tools command + */ + private void registerNBTToolsCommand() { + bukkitCommandManager.registerCommand(new NBTToolsCommand()); + } + + /** + * Register the MMO Debug command + */ + private void registerMmoDebugCommand() { + bukkitCommandManager.registerCommand(new PlayerDebugCommand()); + } + private void registerAddlevelsCommand() { PluginCommand command = pluginRef.getCommand("addlevels"); command.setDescription(pluginRef.getLocaleManager().getString("Commands.Description.addlevels")); @@ -153,16 +191,6 @@ public final class CommandRegistrationManager { command.setExecutor(new MmoInfoCommand(pluginRef)); } - - private void registerMmoDebugCommand() { - PluginCommand command = pluginRef.getCommand("mmodebug"); - command.setDescription(pluginRef.getLocaleManager().getString("Commands.Description.mmodebug")); - command.setPermission(null); //No perm required to save support headaches - command.setPermissionMessage(permissionsMessage); - command.setUsage(pluginRef.getLocaleManager().getString("Commands.Usage.0", "mmodebug")); - command.setExecutor(new PlayerDebugCommand(pluginRef)); - } - private void registerMcChatSpyCommand() { PluginCommand command = pluginRef.getCommand("mcchatspy"); command.setDescription(pluginRef.getLocaleManager().getString("Commands.Description.mcchatspy")); @@ -476,5 +504,8 @@ public final class CommandRegistrationManager { registerMcmmoReloadCommand(); // Admin commands registerReloadLocaleCommand(); + + //ACF Commands + initACF(); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java index 35529853f..022e5288b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java @@ -5,28 +5,30 @@ import com.gmail.nossr50.core.nbt.NBTCompound; import net.minecraft.server.v1_14_R1.NBTTagByte; public class NBTFactory { + //TODO: Finish /** * Converts NMS NBT types into our own NBT type representation * @param nmsNBT target NMS Compound * @return NMS Representation of our NBT */ - public NBTCompound asNBT(net.minecraft.server.v1_14_R1.NBTTagCompound nmsNBT) { - NBTCompound nbtCompound = new NBTCompound(""); +// public NBTCompound asNBT(net.minecraft.server.v1_14_R1.NBTTagCompound nmsNBT) { +// NBTCompound nbtCompound = new NBTCompound(""); +// +// //Traverse the NMS Map +// for(String key : nmsNBT.getKeys()) { +// +// } +// } - //Traverse the NMS Map - for(String key : nmsNBT.getKeys()) { - - } - } - - /** - * Convert our NBT type into the NMS NBT Type equivalent - * @param nbtCompound target nbt compound - * @return NMS NBT copy of our NBT type - */ - public net.minecraft.server.v1_14_R1.NBTTagCompound asNMSCopy(NBTCompound nbtCompound) { - - } + //TODO: Finish +// /** +// * Convert our NBT type into the NMS NBT Type equivalent +// * @param nbtCompound target nbt compound +// * @return NMS NBT copy of our NBT type +// */ +// public net.minecraft.server.v1_14_R1.NBTTagCompound asNMSCopy(NBTCompound nbtCompound) { +// +// } /** * Create a new NMS NBT tag compound with only 1 tag compound named "tag" @@ -40,12 +42,13 @@ public class NBTFactory { return nbtTagCompound; } - private NBTCompound deepCopy(NBTCompound target, String key, net.minecraft.server.v1_14_R1.NBTBase nbtBase) { - switch (nbtBase.getTypeId()) { - case 0: - return new NBTCompound(); - } - } + //TODO: Finish +// private NBTCompound deepCopy(NBTCompound target, String key, net.minecraft.server.v1_14_R1.NBTBase nbtBase) { +// switch (nbtBase.getTypeId()) { +// case 0: +// return new NBTCompound(); +// } +// } /** * Create a NBTByte representation of NBTTagByte (NMS Type) diff --git a/mcmmo-core/src/main/resources/plugin.yml b/mcmmo-core/src/main/resources/plugin.yml index f24b8540f..2e371b8ca 100644 --- a/mcmmo-core/src/main/resources/plugin.yml +++ b/mcmmo-core/src/main/resources/plugin.yml @@ -19,6 +19,9 @@ load: POSTWORLD api-version: 1.13 commands: + nbttools: + description: Modify or Read NBT from an item in hand + permission: mcmmo.commands.nbttools mmodebug: aliases: [mcmmodebugmode] description: Toggles a debug mode which will print useful information to chat @@ -628,6 +631,10 @@ permissions: children: mcmmo.commands.mcconvert.all: true mcmmo.commands.xprate.all: true + mcmmo.commands.nbttools: true + mcmmo.commands.nbttools: + default: false + description: Modify or Read NBT of an item in-hand mcmmo.bypass.*: default: false description: Implies all bypass permissions. From a74f33c96d4e10fd928d917db3f20c1a2946e220 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 9 Feb 2020 16:06:28 -0800 Subject: [PATCH 17/20] Latest changes --- mcmmo-core/build.gradle.kts | 1 + mcmmo-core/src/main/resources/plugin.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index d7743b180..2f241a6de 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -45,6 +45,7 @@ dependencies { api("org.spongepowered:configurate-core:3.7-SNAPSHOT") api("org.spongepowered:configurate-yaml:3.7-SNAPSHOT") api("org.spongepowered:configurate-hocon:3.7-SNAPSHOT") + api("co.aikar:acf-parent:0.5.0-SNAPSHOT") api("co.aikar:acf-bukkit:0.5.0-SNAPSHOT") implementation("org.jetbrains:annotations:17.0.0") implementation("org.apache.maven.scm:maven-scm-provider-gitexe:1.8.1") diff --git a/mcmmo-core/src/main/resources/plugin.yml b/mcmmo-core/src/main/resources/plugin.yml index 2e371b8ca..e4b6123e8 100644 --- a/mcmmo-core/src/main/resources/plugin.yml +++ b/mcmmo-core/src/main/resources/plugin.yml @@ -738,6 +738,7 @@ permissions: mcmmo.commands.mcmmoreload: true mcmmo.commands.mmoedit: true mcmmo.commands.mmoedit.others: true + mcmmo.commands.nbttools: true mcmmo.commands.mmoshowdb: true mcmmo.commands.ptp.world.all: true mcmmo.commands.reloadlocale: true From b34f0d62d62d4514bb81685b53f4510dd4503ecd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 10 Feb 2020 13:13:29 -0800 Subject: [PATCH 18/20] Fixing shadow dependencies (I hope) --- 1 | 11 ------ mcmmo-core/build.gradle.kts | 34 +++++++++++++++---- .../gmail/nossr50/util/nbt/NBTManager.java | 4 +-- 3 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 1 diff --git a/1 b/1 deleted file mode 100644 index c0087c86d..000000000 --- a/1 +++ /dev/null @@ -1,11 +0,0 @@ -SkillShot tweaks -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit. -# -# On branch master -# Your branch is up to date with 'origin/master'. -# -# Changes to be committed: -# modified: src/main/java/com/gmail/nossr50/skills/archery/Archery.java -# modified: src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java -# diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index 2f241a6de..2d67042f8 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -1,4 +1,5 @@ import org.apache.tools.ant.filters.ReplaceTokens +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { `java-library` @@ -7,10 +8,6 @@ plugins { tasks { - build { - dependsOn(shadowJar) - } - shadowJar { dependencies { include(dependency("org.spongepowered:configurate-yaml")) @@ -20,14 +17,24 @@ tasks { include(dependency("org.apache.tomcat:tomcat-jdbc")) include(dependency("org.apache.tomcat:tomcat-juli")) include(dependency("com.typesafe:config")) + include(dependency("co.aikar:acf-core")) include(dependency("co.aikar:acf-bukkit")) +// include(dependency("co.aikar:locales")) +// include(dependency("co.aikar:table")) +// include(dependency("net.jodah:expiring-map")) exclude(dependency("org.spigotmc:spigot")) } relocate("org.apache.commons.logging", "com.gmail.nossr50.commons.logging") relocate("org.apache.juli", "com.gmail.nossr50.database.tomcat.juli") relocate("org.apache.tomcat", "com.gmail.nossr50.database.tomcat") relocate("org.bstats", "com.gmail.nossr50.metrics.bstat") - relocate("co.aikar.commands", "com.gmail.nossr50.acf") + relocate("co.aikar.commands", "com.gmail.nossr50.aikar.commands") + relocate("co.aikar.locales", "com.gmail.nossr50.aikar.locales") + relocate("co.aikar.table", "com.gmail.nossr50.aikar.table") + relocate("net.jodah.expiringmap", "com.gmail.nossr50.expiringmap") + +// archiveBaseName.set("mcMMO") + mergeServiceFiles() } processResources { @@ -36,6 +43,16 @@ tasks { } } + + build { + dependsOn(shadowJar) + } +} + +tasks.named("shadowJar") { + dependencies{ + include { true } + } } @@ -45,8 +62,11 @@ dependencies { api("org.spongepowered:configurate-core:3.7-SNAPSHOT") api("org.spongepowered:configurate-yaml:3.7-SNAPSHOT") api("org.spongepowered:configurate-hocon:3.7-SNAPSHOT") - api("co.aikar:acf-parent:0.5.0-SNAPSHOT") - api("co.aikar:acf-bukkit:0.5.0-SNAPSHOT") + api("co.aikar:acf-core:0.5.0-SNAPSHOT") //Don't change without updating the artifacts for its dependencies (see the other comments) + api("co.aikar:acf-bukkit:0.5.0-SNAPSHOT") //Don't change without updating the artifacts for its dependencies (see the other comments) +// api("co.aikar:locales:1.0-SNAPSHOT") //ACF 0.5.0-SNAPSHOT is dependent on this version of locales +// api("co.aikar:table:1.0.0-SNAPSHOT") //ACF 0.5.0-SNAPSHOT is dependent on this version of table +// api("net.jodah:expiring-map:0.5.8") //ACF 0.5.0-SNAPSHOT is dependent on this version of expiring map implementation("org.jetbrains:annotations:17.0.0") implementation("org.apache.maven.scm:maven-scm-provider-gitexe:1.8.1") implementation("org.bstats:bstats-bukkit:1.4") diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index 4fb1154f7..0c41ee48f 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.util.nbt; -import net.minecraft.server.v1_14_R1.NBTBase; +import com.gmail.nossr50.core.nbt.NBTBase; import net.minecraft.server.v1_14_R1.NBTList; import net.minecraft.server.v1_14_R1.NBTTagCompound; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; @@ -149,7 +149,7 @@ public class NBTManager { } } - public NBTBase constructNBT(String nbtString) { + public net.minecraft.server.v1_14_R1.NBTBase constructNBT(String nbtString) { try { return CraftNBTTagConfigSerializer.deserialize(nbtString); } catch (Exception e) { From 63de093ebb5fc85df7afc01a5146857ac0df7bcf Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 10 Feb 2020 13:18:42 -0800 Subject: [PATCH 19/20] Remove debug on swing --- .../nossr50/listeners/PlayerListener.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index c48d7db5e..995ce8482 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -901,17 +901,17 @@ public class PlayerListener implements Listener { } } - @EventHandler(priority = EventPriority.LOWEST) - public void onDebugPlayerInteract(PlayerInteractEvent event) { - if(pluginRef.getUserManager().getPlayer(event.getPlayer()) != null) { - McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(event.getPlayer()); - if(mcMMOPlayer.isDebugMode()) { - switch(event.getAction()) { - case LEFT_CLICK_AIR: - case LEFT_CLICK_BLOCK: - pluginRef.getNbtManager().debugNBTInMainHandItem(event.getPlayer()); - } - } - } - } +// @EventHandler(priority = EventPriority.LOWEST) +// public void onDebugPlayerInteract(PlayerInteractEvent event) { +// if(pluginRef.getUserManager().getPlayer(event.getPlayer()) != null) { +// McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(event.getPlayer()); +// if(mcMMOPlayer.isDebugMode()) { +// switch(event.getAction()) { +// case LEFT_CLICK_AIR: +// case LEFT_CLICK_BLOCK: +// pluginRef.getNbtManager().debugNBTInMainHandItem(event.getPlayer()); +// } +// } +// } +// } } From 4ff4def56a4cbcf450ced00aa36d0093d8b86b7c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 10 Feb 2020 13:19:14 -0800 Subject: [PATCH 20/20] Optimize imports --- mcmmo-core/build.gradle.kts | 2 +- .../src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index 2d67042f8..0a1cac572 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -1,5 +1,5 @@ -import org.apache.tools.ant.filters.ReplaceTokens import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.apache.tools.ant.filters.ReplaceTokens plugins { `java-library` diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java index 022e5288b..208a7e658 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTFactory.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.util.nbt; import com.gmail.nossr50.core.nbt.NBTByte; -import com.gmail.nossr50.core.nbt.NBTCompound; import net.minecraft.server.v1_14_R1.NBTTagByte; public class NBTFactory {