From 0509f4f63eedd25ad3d4dfd13a91162742ed94df Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 30 Sep 2019 16:47:47 -0700 Subject: [PATCH 01/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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 dceee5554d3241123e3ea656ee25c633a7c86203 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 28 Jan 2020 16:32:28 +0000 Subject: [PATCH 16/44] Fix CombatUtils NPE due to arrows from unloaded players --- .../com/gmail/nossr50/listeners/EntityListener.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 17e18fb4d..2f191cc6e 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -381,12 +381,15 @@ public class EntityListener implements Listener { } //Deflect checks - UnarmedManager unarmedManager = UserManager.getPlayer(defendingPlayer).getUnarmedManager(); + final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(defendingPlayer); + if (mcMMOPlayer != null) { + UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); - if (unarmedManager.canDeflect()) { - if(unarmedManager.deflectCheck()) { - event.setCancelled(true); - return; + if (unarmedManager.canDeflect()) { + if (unarmedManager.deflectCheck()) { + event.setCancelled(true); + return; + } } } } else { From 816b64cb7089685a2adaf179e2049221c9bd50ce Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 28 Jan 2020 16:37:02 +0000 Subject: [PATCH 17/44] Track spectral arrows for combat --- Changelog.txt | 4 ++++ src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index 354ea638e..3a2b5ef9b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,7 @@ +Version 2.1.115 + Fixed an issue with arrows causing exceptions with players not yet having data loaded + Spectral arrows are now tracked by mcMMO + Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales Fixed a bug where newer versions of MySQL did not like our rank command diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index bf5539c0b..99a1ee9f4 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -380,7 +380,7 @@ public final class CombatUtils { } } } - else if (entityType == EntityType.ARROW) { + else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { Arrow arrow = (Arrow) damager; ProjectileSource projectileSource = arrow.getShooter(); From 4eef4a3e417dcbf9dd45ad9bf6288fa0107c72ab Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 4 Feb 2020 23:29:51 +0000 Subject: [PATCH 18/44] Fix CCE from spectral arrows (Fixes #4114) --- src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 99a1ee9f4..fa6e052b9 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -221,7 +221,7 @@ public final class CombatUtils { } - private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) { + private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, AbstractArrow arrow) { double initialDamage = event.getDamage(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); @@ -381,7 +381,7 @@ public final class CombatUtils { } } else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { - Arrow arrow = (Arrow) damager; + AbstractArrow arrow = (AbstractArrow) damager; ProjectileSource projectileSource = arrow.getShooter(); if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) { From 11ca0d9ff101cd77f5e26dcacbc3a666c4ac305e Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 4 Feb 2020 23:36:54 +0000 Subject: [PATCH 19/44] Fix 1.13.x archery compat --- src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index fa6e052b9..42afeeca3 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -221,7 +221,7 @@ public final class CombatUtils { } - private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, AbstractArrow arrow) { + private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Projectile arrow) { double initialDamage = event.getDamage(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); @@ -381,7 +381,7 @@ public final class CombatUtils { } } else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { - AbstractArrow arrow = (AbstractArrow) damager; + Projectile arrow = (Projectile) damager; ProjectileSource projectileSource = arrow.getShooter(); if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) { From 359e3e34ad34e106a4f8004c704705d3442e94c9 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 7 Feb 2020 13:28:17 -0800 Subject: [PATCH 20/44] Unused import --- .../com/gmail/nossr50/config/skills/ranks/SkillRankProperty.java | 1 - 1 file changed, 1 deletion(-) 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; From 24ba3b1a0125c1ac2096e69322854c7f903497ef Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 7 Feb 2020 15:06:00 -0800 Subject: [PATCH 21/44] 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 4f161812aa85c6fb138b4d6d69233dd103a13003 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 9 Feb 2020 22:47:17 +0000 Subject: [PATCH 22/44] Use minimum level of salvagable properly --- .../com/gmail/nossr50/skills/salvage/SalvageManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 02a20cec2..5d3cc1134 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -82,11 +82,11 @@ public class SalvageManager extends SkillManager { return; } - /*int skillLevel = getSkillLevel(); - int minimumSalvageableLevel = salvageable.getMinimumLevel();*/ + /*int skillLevel = getSkillLevel();*/ + int minimumSalvageableLevel = salvageable.getMinimumLevel(); // Level check - if (!RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR)) { + if (getSkillLevel() < minimumSalvageableLevel) { NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Salvage.Skills.Adept.Level", String.valueOf(RankUtils.getUnlockLevel(SubSkillType.SALVAGE_ARCANE_SALVAGE)), StringUtils.getPrettyItemString(item.getType())); return; } From 8e8024e3e1d52f6803948eeadb85dc9539460746 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 9 Feb 2020 22:50:28 +0000 Subject: [PATCH 23/44] update changelog --- Changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.txt b/Changelog.txt index 3a2b5ef9b..9f373f01f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,7 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO + Use minimum level of salvageable properly Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales From a74f33c96d4e10fd928d917db3f20c1a2946e220 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 9 Feb 2020 16:06:28 -0800 Subject: [PATCH 24/44] 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 25/44] 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 26/44] 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 27/44] 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 { From 2d342f8a3d58567faf0bb92beb042a5e7f371072 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 11 Feb 2020 15:44:52 -0800 Subject: [PATCH 28/44] Missing default tag --- .../com/gmail/nossr50/commands/admin/PlayerDebugCommand.java | 2 ++ 1 file changed, 2 insertions(+) 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 a0f885c37..6250d2a2d 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,6 +1,7 @@ package com.gmail.nossr50.commands.admin; import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Dependency; import co.aikar.commands.annotation.Description; import com.gmail.nossr50.datatypes.player.McMMOPlayer; @@ -15,6 +16,7 @@ public class PlayerDebugCommand extends BaseCommand { @Dependency private mcMMO pluginRef; + @Default public void onCommand(CommandSender sender) { if(sender instanceof Player) { McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer((Player) sender); From 38d64f207d0532f8158eb9cfc0c8be3261c02200 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 12 Feb 2020 02:06:49 +0000 Subject: [PATCH 29/44] Fix default permission for Critical Strikes --- Changelog.txt | 1 + src/main/resources/plugin.yml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 9f373f01f..232675755 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,6 +2,7 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly + Fix axes Critical Strikes default permissions Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7f23ba9a3..7006f2318 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -273,7 +273,7 @@ permissions: description: Allows access to all Axes abilities children: mcmmo.ability.axes.axemastery: true - mcmmo.ability.axes.criticalhit: true + mcmmo.ability.axes.criticalstrikes: true mcmmo.ability.axes.greaterimpact: true mcmmo.ability.axes.armorimpact: true mcmmo.ability.axes.skullsplitter: true @@ -282,8 +282,8 @@ permissions: description: Adds damage to axes mcmmo.ability.axes.axemastery: description: Allows bonus damage from Axes - mcmmo.ability.axes.criticalhit: - description: Allows access to the Critical Hit ability + mcmmo.ability.axes.criticalstrikes: + description: Allows access to the Critical Strikes ability mcmmo.ability.axes.greaterimpact: description: Allows access to the Greater Impact ability mcmmo.ability.axes.armorimpact: From f45c70b69498a02e73a532bd51e822e2bc49c561 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 12 Feb 2020 15:20:21 -0800 Subject: [PATCH 30/44] More work on ACF integration --- mcmmo-core/build.gradle.kts | 2 +- .../commands/admin/NBTToolsCommand.java | 9 +- .../commands/admin/PlayerDebugCommand.java | 8 +- .../main/java/com/gmail/nossr50/mcMMO.java | 1 + .../commands/CommandRegistrationManager.java | 99 +++++++++++-------- mcmmo-core/src/main/resources/plugin.yml | 6 -- 6 files changed, 73 insertions(+), 52 deletions(-) diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index 0a1cac572..53ce74c35 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -63,7 +63,7 @@ dependencies { api("org.spongepowered:configurate-yaml:3.7-SNAPSHOT") api("org.spongepowered:configurate-hocon:3.7-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:acf-paper: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 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 index 82a63daab..fcbb129b7 100644 --- 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 @@ -1,15 +1,22 @@ package com.gmail.nossr50.commands.admin; import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Dependency; import co.aikar.commands.annotation.Description; import com.gmail.nossr50.mcMMO; +import org.bukkit.entity.Player; +@CommandAlias("nbttools") @Description("Read or Modify values of NBT on an item in-hand") public class NBTToolsCommand extends BaseCommand { @Dependency private mcMMO pluginRef; - + @Default + public void onCommand(Player player) { + player.sendMessage("hi"); + } } 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 6250d2a2d..6e8f58038 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,6 +1,7 @@ package com.gmail.nossr50.commands.admin; import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Dependency; import co.aikar.commands.annotation.Description; @@ -10,18 +11,19 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandAlias("mmodebug") @Description("Puts the player into debug mode, which helps problem solve bugs in mcMMO.") public class PlayerDebugCommand extends BaseCommand { @Dependency - private mcMMO pluginRef; + private mcMMO plugin; @Default public void onCommand(CommandSender sender) { if(sender instanceof Player) { - McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer((Player) sender); + McMMOPlayer mcMMOPlayer = plugin.getUserManager().getPlayer((Player) sender); mcMMOPlayer.toggleDebugMode(); //Toggle debug mode - pluginRef.getNotificationManager().sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode())); + plugin.getNotificationManager().sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode())); } else { //TODO: Localize sender.sendMessage("Players only"); 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 8108cf4b1..64f0d801f 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -218,6 +218,7 @@ public class mcMMO extends JavaPlugin { scheduleTasks(); commandRegistrationManager = new CommandRegistrationManager(this); + commandRegistrationManager.registerACFCommands(); commandRegistrationManager.registerCommands(); nbtManager = new NBTManager(); 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 75068f146..dc42788b0 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,6 @@ package com.gmail.nossr50.util.commands; -import co.aikar.commands.BukkitCommandManager; +import co.aikar.commands.PaperCommandManager; import com.gmail.nossr50.commands.*; import com.gmail.nossr50.commands.admin.NBTToolsCommand; import com.gmail.nossr50.commands.admin.PlayerDebugCommand; @@ -29,15 +29,70 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +//TODO: Properly rewrite ACF integration later public final class CommandRegistrationManager { private final mcMMO pluginRef; private String permissionsMessage; - private BukkitCommandManager bukkitCommandManager; + //NOTE: Does not actually require paper, will work for bukkit + private PaperCommandManager commandManager; public CommandRegistrationManager(mcMMO pluginRef) { this.pluginRef = pluginRef; permissionsMessage = pluginRef.getLocaleManager().getString("mcMMO.NoPermission"); - bukkitCommandManager = new BukkitCommandManager(pluginRef); + commandManager = new PaperCommandManager(pluginRef); + } + + /** + * Register ACF Commands + */ + //TODO: Properly rewrite ACF integration later + public void registerACFCommands() { + //Register ACF Commands + registerNBTToolsCommand(); + registerMmoDebugCommand(); + } + + /** + * Register exception handlers for the ACF commands + */ + //TODO: Properly rewrite ACF integration later + private void registerExceptionHandlers() { + registerDefaultExceptionHandler(); + } + + /** + * Register default exception handler + */ + //TODO: Properly rewrite ACF integration later + private void registerDefaultExceptionHandler() { + commandManager.setDefaultExceptionHandler((command, registeredCommand, sender, args, t) -> { + pluginRef.getLogger().warning("Error occurred while executing command " + command.getName()); + return false; + }); + } + + /** + * Register contexts for ACF + */ + //TODO: Properly rewrite ACF integration later + private void registerContexts() { + + } + + /** + * Register the NBT Tools command + */ + //TODO: Properly rewrite ACF integration later + private void registerNBTToolsCommand() { + commandManager.registerCommand(new NBTToolsCommand()); + } + + /** + * Register the MMO Debug command + */ + //TODO: Properly rewrite ACF integration later + private void registerMmoDebugCommand() { + commandManager.registerCommand(new PlayerDebugCommand()); } private void registerSkillCommands() { @@ -121,40 +176,6 @@ 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")); @@ -455,7 +476,6 @@ public final class CommandRegistrationManager { public void registerCommands() { // Generic Commands registerMmoInfoCommand(); - registerMmoDebugCommand(); registerMcabilityCommand(); registerMcgodCommand(); registerMcChatSpyCommand(); @@ -504,8 +524,5 @@ public final class CommandRegistrationManager { registerMcmmoReloadCommand(); // Admin commands registerReloadLocaleCommand(); - - //ACF Commands - initACF(); } } diff --git a/mcmmo-core/src/main/resources/plugin.yml b/mcmmo-core/src/main/resources/plugin.yml index e4b6123e8..5193447cd 100644 --- a/mcmmo-core/src/main/resources/plugin.yml +++ b/mcmmo-core/src/main/resources/plugin.yml @@ -19,12 +19,6 @@ 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 mmoinfo: aliases: [mcinfo] description: Info pages for mcMMO From 3c382a11edd93e7761060271f42a1997663dacd5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 17 Feb 2020 18:30:09 -0800 Subject: [PATCH 31/44] Add showtags subcommand to nbttools --- .../commands/admin/NBTToolsCommand.java | 32 ++++++++++++++++--- .../gmail/nossr50/util/nbt/NBTManager.java | 32 +++++++++++++++++-- 2 files changed, 56 insertions(+), 8 deletions(-) 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 index fcbb129b7..1b16e9e2e 100644 --- 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 @@ -1,22 +1,44 @@ package com.gmail.nossr50.commands.admin; import co.aikar.commands.BaseCommand; -import co.aikar.commands.annotation.CommandAlias; -import co.aikar.commands.annotation.Default; -import co.aikar.commands.annotation.Dependency; -import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.*; import com.gmail.nossr50.mcMMO; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; @CommandAlias("nbttools") @Description("Read or Modify values of NBT on an item in-hand") public class NBTToolsCommand extends BaseCommand { + public static final String STYLE_TEXT_1 = "//////////"; @Dependency - private mcMMO pluginRef; + private mcMMO plugin; @Default public void onCommand(Player player) { player.sendMessage("hi"); } + + /** + * Show the NBT tags of an item in hand + */ + @Subcommand("showtags") + public void onShowTags(Player player) { + //Show NBT tags to player + player.sendMessage(STYLE_TEXT_1 + " NBT TOOLS " + STYLE_TEXT_1); + player.sendMessage("NBT Analysis: " + player.getInventory().getItemInMainHand().getType().getKey().toString()); + player.sendMessage(STYLE_TEXT_1 + STYLE_TEXT_1); + plugin.getNbtManager().printNBT(player.getInventory().getItemInMainHand(), player); + player.sendMessage(ChatColor.GRAY + "NBT Analysis completed!"); + } + + @Subcommand("add") + public void onAddTags(Player player) { + + } + + @Subcommand("remove") + public void onRemoveTags(Player player) { + + } } 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 0c41ee48f..d9d749916 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,6 +4,7 @@ package com.gmail.nossr50.util.nbt; 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.ChatColor; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer; import org.bukkit.entity.Player; @@ -166,11 +167,36 @@ public class NBTManager { */ public void printNBT(ItemStack itemStack, Player player) { NBTTagCompound tagCompoundCopy = getNBTCopy(itemStack); - for(String key : tagCompoundCopy.getKeys()) { + printNBT(tagCompoundCopy, player); + } + + private void printNBT(NBTTagCompound nbtTagCompound, Player player) { + for(String key : nbtTagCompound.getKeys()) { player.sendMessage(""); - player.sendMessage("NBT Key: "+key); - player.sendMessage("NBT Value: " + tagCompoundCopy.get(key).asString()); + + net.minecraft.server.v1_14_R1.NBTBase targetTag = nbtTagCompound.get(key); + + //Recursively print contents + if(targetTag instanceof NBTTagCompound) { + NBTTagCompound childTagCompound = nbtTagCompound.getCompound(key); + if(childTagCompound != null) { + player.sendMessage(ChatColor.BLUE + "NBT named " + ChatColor.GOLD + key + ChatColor.BLUE + " is a tag compound, printing contents..."); + printNBT(childTagCompound, player); + player.sendMessage(ChatColor.BLUE + "Exiting "+ key); + continue; + } + } + + player.sendMessage(ChatColor.GOLD + "Tag Key: " + ChatColor.RESET + key); + + if(targetTag == null) { + player.sendMessage(ChatColor.RED + "Tag is null!"); + continue; + } + + player.sendMessage(ChatColor.GREEN + "Tag Value: " + ChatColor.RESET + targetTag.asString()); } + } public boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) { From 85550c5750abc14361676cca4a574bbb870fb3f1 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 17 Feb 2020 18:46:48 -0800 Subject: [PATCH 32/44] Add kashike's text lib to dependencies --- mcmmo-core/build.gradle.kts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index 53ce74c35..4f81ae5cb 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -19,9 +19,7 @@ tasks { 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")) + include(dependency("net.kyori:text-api")) exclude(dependency("org.spigotmc:spigot")) } relocate("org.apache.commons.logging", "com.gmail.nossr50.commons.logging") @@ -32,8 +30,8 @@ tasks { 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") + relocate("net.kyori.text", "com.gmail.nossr50.kashike.text") -// archiveBaseName.set("mcMMO") mergeServiceFiles() } @@ -64,9 +62,7 @@ dependencies { api("org.spongepowered:configurate-hocon:3.7-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-paper: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 + api("net.kyori:text-api:3.0.0") 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") From c071471bdf006bacbe6bc8b38d7a994c35e264a5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 17 Feb 2020 19:27:21 -0800 Subject: [PATCH 33/44] update for text libs --- mcmmo-core/build.gradle.kts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mcmmo-core/build.gradle.kts b/mcmmo-core/build.gradle.kts index 4f81ae5cb..f7b696329 100644 --- a/mcmmo-core/build.gradle.kts +++ b/mcmmo-core/build.gradle.kts @@ -20,6 +20,8 @@ tasks { include(dependency("co.aikar:acf-core")) include(dependency("co.aikar:acf-bukkit")) include(dependency("net.kyori:text-api")) + include(dependency("net.kyori:text-adapter-bukkit")) + include(dependency("net.kyori:text-serializer-gson")) exclude(dependency("org.spigotmc:spigot")) } relocate("org.apache.commons.logging", "com.gmail.nossr50.commons.logging") @@ -30,7 +32,7 @@ tasks { 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") - relocate("net.kyori.text", "com.gmail.nossr50.kashike.text") + relocate("net.kyori.text", "com.gmail.nossr50.kyoripowered.text") mergeServiceFiles() } @@ -62,7 +64,9 @@ dependencies { api("org.spongepowered:configurate-hocon:3.7-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-paper:0.5.0-SNAPSHOT") //Don't change without updating the artifacts for its dependencies (see the other comments) - api("net.kyori:text-api:3.0.0") + api("net.kyori:text-api:3.0.2") + api("net.kyori:text-serializer-gson:3.0.2") + api("net.kyori:text-adapter-bukkit:3.0.4-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") From 19a4c0238f3ed09e3d9a468a8072637059e88f56 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 17 Feb 2020 19:34:10 -0800 Subject: [PATCH 34/44] add sonatype --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index f84c06abb..1ee93ce4e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ subprojects { repositories { mavenLocal() mavenCentral() + maven("https://oss.sonatype.org/content/groups/public/") maven("https://repo.spongepowered.org/maven") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots") maven("https://repo.codemc.org/repository/maven-public") From ab6dbe306d04e0d66fe5429d8a3128cab63bdb3c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 11:38:48 -0800 Subject: [PATCH 35/44] Fix potential NPE for salvage --- Changelog.txt | 3 ++- .../java/com/gmail/nossr50/skills/salvage/SalvageManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 232675755..53227539a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,7 +2,8 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly - Fix axes Critical Strikes default permissions + Fix Axes Critical Strikes default permissions ( new fixed permission: mcmmo.ability.axes.criticalstrikes ) + Fix potential null pointer exception for salvage Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 5d3cc1134..327cfcd95 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -66,7 +66,7 @@ public class SalvageManager extends SkillManager { Salvageable salvageable = mcMMO.getSalvageableManager().getSalvageable(item.getType()); - if (item.getItemMeta().isUnbreakable()) { + if (item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) { NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable"); return; } From 4e21f1a2009689872d9867d9be34c5087c516b44 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 13:27:21 -0800 Subject: [PATCH 36/44] tweak and fix salvage result chance --- Changelog.txt | 1 + .../com/gmail/nossr50/skills/herbalism/HerbalismManager.java | 3 +-- .../java/com/gmail/nossr50/skills/salvage/SalvageManager.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 53227539a..adaf42ab0 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.115 + Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 18547bd99..9b6a68881 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -437,8 +437,7 @@ public class HerbalismManager extends SkillManager { } private HashSet getBrokenChorusBlocks(BlockState originalBreak) { - HashSet traversedBlocks = grabChorusTreeBrokenBlocksRecursive(originalBreak.getBlock(), new HashSet<>()); - return traversedBlocks; + return grabChorusTreeBrokenBlocksRecursive(originalBreak.getBlock(), new HashSet<>()); } private HashSet grabChorusTreeBrokenBlocksRecursive(Block currentBlock, HashSet traversed) { diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 327cfcd95..063fd746e 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -118,8 +118,8 @@ public class SalvageManager extends SkillManager { for(int x = 0; x < potentialSalvageYield-1; x++) { if(RandomChanceUtil.rollDice(chanceOfSuccess, 100)) { - chanceOfSuccess-=2; - Math.max(chanceOfSuccess, 95); + chanceOfSuccess-=3; + chanceOfSuccess = Math.max(chanceOfSuccess, 90); lotteryResults+=1; } From 8f265441884a2aba2b359cd924b25eda2ac74199 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 13:51:10 -0800 Subject: [PATCH 37/44] Immature plants will be replanted if weilding a hoe --- Changelog.txt | 1 + .../skills/herbalism/HerbalismManager.java | 37 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index adaf42ab0..69da6676f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.115 + Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 9b6a68881..3eb0951f2 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -143,6 +143,9 @@ public class HerbalismManager extends SkillManager { //Grab all broken blocks HashSet brokenBlocks = getBrokenHerbalismBlocks(blockBreakEvent); + if(brokenBlocks.size() == 0) + return; + //Handle rewards, xp, ability interactions, etc processHerbalismOnBlocksBroken(blockBreakEvent, brokenBlocks); } @@ -157,7 +160,12 @@ public class HerbalismManager extends SkillManager { //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - processGreenThumbPlants(originalBreak, isGreenTerraActive()); + processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + } + + //When replanting a immature crop we cancel the block break event and back out + if(blockBreakEvent.isCancelled()) { + return; } /* @@ -339,9 +347,11 @@ public class HerbalismManager extends SkillManager { //Calculate XP if(plantData instanceof Ageable) { Ageable plantAgeable = (Ageable) plantData; + if(isAgeableMature(plantAgeable) || isBizarreAgeable(plantData)) { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenBlockNewState.getType()); } + } else { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenPlantBlock.getType()); } @@ -635,10 +645,18 @@ public class HerbalismManager extends SkillManager { * @param blockState The {@link BlockState} to check ability activation for * @param greenTerra boolean to determine if greenTerra is active or not */ - private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) { - if (!BlockUtils.isFullyGrown(blockState)) + private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + BlockData blockData = blockState.getBlockData(); + + if (!(blockData instanceof Ageable)) return; + //If the ageable is NOT mature and the player is NOT using a hoe, abort + if(!isAgeableMature((Ageable) blockData) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { + return; + } + + Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); Material seed = null; @@ -678,7 +696,7 @@ public class HerbalismManager extends SkillManager { return; } - if (!processGrowingPlants(blockState, greenTerra)) { + if (!processGrowingPlants(blockState, blockBreakEvent, greenTerra)) { return; } @@ -695,11 +713,18 @@ public class HerbalismManager extends SkillManager { new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } - private boolean processGrowingPlants(BlockState blockState, boolean greenTerra) { + private boolean processGrowingPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + Ageable crops = (Ageable) blockState.getBlockData(); int greenThumbStage = getGreenThumbStage(); + //Immature plants will start over at 0 + if(!isAgeableMature(crops)) { + crops.setAge(0); + blockBreakEvent.setCancelled(true); + return true; + } + blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); - Ageable crops = (Ageable) blockState.getBlockData(); switch (blockState.getType()) { From e2073ff9f7c8fe92ebf8c0fb785ce5cfba4958c0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 15:58:53 -0800 Subject: [PATCH 38/44] Immature crop replanting, green thumb tweaks, replant accidental break protection --- Changelog.txt | 2 + .../gmail/nossr50/datatypes/meta/OldName.java | 1 + .../meta/RecentlyReplantedCropMeta.java | 17 ++++ src/main/java/com/gmail/nossr50/mcMMO.java | 1 + .../runnables/skills/DelayedCropReplant.java | 90 +++++++++++++++++++ .../skills/herbalism/HerbalismManager.java | 75 +++++++++++----- .../util/skills/ParticleEffectUtils.java | 15 +++- .../nossr50/util/sounds/SoundManager.java | 5 ++ 8 files changed, 179 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java create mode 100644 src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java diff --git a/Changelog.txt b/Changelog.txt index 69da6676f..a10e35f58 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Hoes no longer give free replants + There is now a feature in place to prevent breaking a newly automatically replanted (via green thumb) crop from being breakable for a few seconds after it appears Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java b/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java index b300f92cc..137399009 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java @@ -12,4 +12,5 @@ public class OldName extends FixedMetadataValue { { super(plugin, oldName); } + } diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java new file mode 100644 index 000000000..5c630f7bc --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java @@ -0,0 +1,17 @@ +package com.gmail.nossr50.datatypes.meta; + +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.plugin.Plugin; + +public class RecentlyReplantedCropMeta extends FixedMetadataValue { + + /** + * Initializes a FixedMetadataValue with an Object + * + * @param owningPlugin the {@link Plugin} that created this metadata value + */ + public RecentlyReplantedCropMeta(Plugin owningPlugin) { + super(owningPlugin, true); + } + +} diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index b28777238..0306f6d68 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -107,6 +107,7 @@ public class mcMMO extends JavaPlugin { private static boolean isRetroModeEnabled; /* Metadata Values */ + public final static String REPLANT_META_KEY = "mcMMO: Recently Replanted"; public static final String FISH_HOOK_REF_METAKEY = "mcMMO: Fish Hook Tracker"; public static final String DODGE_TRACKER = "mcMMO: Dodge Tracker"; public static final String CUSTOM_DAMAGE_METAKEY = "mcMMO: Custom Damage"; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java new file mode 100644 index 000000000..d19411b5e --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -0,0 +1,90 @@ +package com.gmail.nossr50.runnables.skills; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.skills.ParticleEffectUtils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.Ageable; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class DelayedCropReplant extends BukkitRunnable { + + private final int desiredCropAge; + private final Location cropLocation; + private final Material cropMaterial; + private boolean wasImmaturePlant; + private final BlockBreakEvent blockBreakEvent; + + /** + * Replants a crop after a delay setting the age to desiredCropAge + * @param cropState target {@link BlockState} + * @param desiredCropAge desired age of the crop + */ + public DelayedCropReplant(BlockBreakEvent blockBreakEvent, BlockState cropState, int desiredCropAge, boolean wasImmaturePlant) { + //The plant was either immature or something cancelled the event, therefor we need to treat it differently + this.blockBreakEvent = blockBreakEvent; + this.wasImmaturePlant = wasImmaturePlant; + this.cropMaterial = cropState.getType(); + this.desiredCropAge = desiredCropAge; + this.cropLocation = cropState.getLocation(); + } + + @Override + public void run() { + Block cropBlock = cropLocation.getBlock(); + BlockState currentState = cropBlock.getState(); + + if(blockBreakEvent.isCancelled()) { + wasImmaturePlant = true; + } + + //Two kinds of air in Minecraft + if(currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { + //The space is not currently occupied by a block so we can fill it + cropBlock.setType(cropMaterial); + + //Get new state (necessary?) + BlockState newState = cropBlock.getState(); + newState.setType(cropMaterial); + newState.update(); + Ageable ageable = (Ageable) newState.getBlockData(); + + //Crop age should always be 0 if the plant was immature + if(wasImmaturePlant) { + ageable.setAge(0); + } else { + //Otherwise make the plant the desired age + ageable.setAge(desiredCropAge); + } + + //Age the crop + newState.setBlockData(ageable); + + //Play an effect + ParticleEffectUtils.playGreenThumbEffect(cropLocation); + + //Remove the metadata marking the block as recently replanted + new removePlantMeta(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20); + } + + } + + private class removePlantMeta extends BukkitRunnable { + + private final Location cropLoc; + + public removePlantMeta(Location cropLoc) { + this.cropLoc = cropLoc; + } + + @Override + public void run() { + Block cropBlock = cropLoc.getBlock(); + cropBlock.removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + } + } + +} diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 3eb0951f2..69cd04b6e 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.BlockSnapshot; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.interactions.NotificationType; +import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; @@ -14,6 +15,7 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.runnables.skills.DelayedCropReplant; import com.gmail.nossr50.runnables.skills.DelayedHerbalismXPCheckTask; import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.skills.SkillManager; @@ -158,6 +160,13 @@ public class HerbalismManager extends SkillManager { private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet brokenPlants) { BlockState originalBreak = blockBreakEvent.getBlock().getState(); + //Check if the plant was recently replanted + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + return; + } + //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); @@ -639,6 +648,18 @@ public class HerbalismManager extends SkillManager { return Herbalism.convertShroomThumb(blockState); } + /** + * Starts the delayed replant task and turns + * @param desiredCropAge the desired age of the crop + * @param blockBreakEvent the {@link BlockBreakEvent} this crop was involved in + * @param cropState the {@link BlockState} of the crop + */ + private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) { + //Mark the plant as recently replanted to avoid accidental breakage + blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p)); + new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge, isImmature).runTaskLater(mcMMO.p, 20 * 2); + } + /** * Process the Green Thumb ability for plants. * @@ -651,12 +672,13 @@ public class HerbalismManager extends SkillManager { if (!(blockData instanceof Ageable)) return; + Ageable ageable = (Ageable) blockData; + //If the ageable is NOT mature and the player is NOT using a hoe, abort - if(!isAgeableMature((Ageable) blockData) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { + if(!isAgeableMature(ageable) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { return; } - Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); Material seed = null; @@ -696,31 +718,36 @@ public class HerbalismManager extends SkillManager { return; } - if (!processGrowingPlants(blockState, blockBreakEvent, greenTerra)) { + + if (!playerInventory.containsAtLeast(seedStack, 1)) { return; } - if(!ItemUtils.isHoe(getPlayer().getInventory().getItemInMainHand())) - { - if (!playerInventory.containsAtLeast(seedStack, 1)) { - return; - } - - playerInventory.removeItem(seedStack); - player.updateInventory(); // Needed until replacement available + if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) { + return; } + playerInventory.removeItem(seedStack); + player.updateInventory(); // Needed until replacement available + new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } - private boolean processGrowingPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { - Ageable crops = (Ageable) blockState.getBlockData(); + private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + //This check is needed + if(isBizarreAgeable(ageable)) { + return false; + } + + int finalAge = 0; int greenThumbStage = getGreenThumbStage(); //Immature plants will start over at 0 - if(!isAgeableMature(crops)) { - crops.setAge(0); + if(!isAgeableMature(ageable)) { blockBreakEvent.setCancelled(true); + startReplantTask(0, blockBreakEvent, blockState, true); + blockState.setType(Material.AIR); + blockState.update(); return true; } @@ -733,10 +760,10 @@ public class HerbalismManager extends SkillManager { case WHEAT: if (greenTerra) { - crops.setAge(3); + finalAge = 3; } else { - crops.setAge(greenThumbStage); + finalAge = getGreenThumbStage(); } break; @@ -744,30 +771,32 @@ public class HerbalismManager extends SkillManager { case NETHER_WART: if (greenTerra || greenThumbStage > 2) { - crops.setAge(2); + finalAge = 2; } else if (greenThumbStage == 2) { - crops.setAge(1); + finalAge = 1; } else { - crops.setAge(0); + finalAge = 0; } break; case COCOA: if (greenTerra || getGreenThumbStage() > 1) { - crops.setAge(1); + finalAge = 1; } else { - crops.setAge(0); + finalAge = 0; } break; default: return false; } - blockState.setBlockData(crops); + + //Start the delayed replant + startReplantTask(finalAge, blockBreakEvent, blockState, false); return true; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java index 76cc10308..4ddf909af 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.util.skills; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.util.sounds.SoundManager; +import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -14,6 +16,12 @@ public final class ParticleEffectUtils { private ParticleEffectUtils() {}; + public static void playGreenThumbEffect(Location location) { + World world = location.getWorld(); + playSmokeEffect(location); + SoundManager.worldSendSoundMaxPitch(world, location, SoundType.POP); + } + public static void playBleedEffect(LivingEntity livingEntity) { if (!Config.getInstance().getBleedEffectEnabled()) { return; @@ -27,7 +35,7 @@ public final class ParticleEffectUtils { return; } - playSmokeEffect(player); + playSmokeEffect(player.getLocation()); } public static void playFluxEffect(Location location) { @@ -38,9 +46,8 @@ public final class ParticleEffectUtils { location.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES, 1); } - public static void playSmokeEffect(LivingEntity livingEntity) { - Location location = livingEntity.getEyeLocation(); - World world = livingEntity.getWorld(); + public static void playSmokeEffect(Location location) { + World world = location.getWorld(); // Have to do it this way, because not all block directions are valid for smoke world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_EAST); diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java index 8bf24461f..fdb4e4e80 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java @@ -39,6 +39,11 @@ public class SoundManager { world.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType)); } + public static void worldSendSoundMaxPitch(World world, Location location, SoundType soundType) { + if(SoundConfig.getInstance().getIsEnabled(soundType)) + world.playSound(location, getSound(soundType), getVolume(soundType), 2.0F); + } + /** * All volume is multiplied by the master volume to get its final value * @param soundType target soundtype From 7c6d5c476d28295d138b874a02653e7ec0c30334 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 16:14:21 -0800 Subject: [PATCH 39/44] Green Thumb requires a hoe, sneak to break with a hoe --- Changelog.txt | 2 ++ .../nossr50/skills/herbalism/HerbalismManager.java | 14 ++++++++++---- .../gmail/nossr50/util/sounds/SoundManager.java | 2 ++ .../com/gmail/nossr50/util/sounds/SoundType.java | 1 + src/main/resources/sounds.yml | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index a10e35f58..15d7084df 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Green Thumb now requires a hoe to activate + You can sneak to break plants with a hoe in your hand (or just put the hoe away) Hoes no longer give free replants There is now a feature in place to prevent breaking a newly automatically replanted (via green thumb) crop from being breakable for a few seconds after it appears Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 69cd04b6e..c7a91cfc0 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -26,6 +26,8 @@ import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillUtils; +import com.gmail.nossr50.util.sounds.SoundManager; +import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -667,17 +669,19 @@ public class HerbalismManager extends SkillManager { * @param greenTerra boolean to determine if greenTerra is active or not */ private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + if(blockBreakEvent.getPlayer().isSneaking() || !ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { + return; + } + BlockData blockData = blockState.getBlockData(); - if (!(blockData instanceof Ageable)) + if (!(blockData instanceof Ageable)) { return; + } Ageable ageable = (Ageable) blockData; //If the ageable is NOT mature and the player is NOT using a hoe, abort - if(!isAgeableMature(ageable) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { - return; - } Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); @@ -729,6 +733,8 @@ public class HerbalismManager extends SkillManager { playerInventory.removeItem(seedStack); player.updateInventory(); // Needed until replacement available + //Play sound + SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED); new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java index fdb4e4e80..a3d7bc736 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java @@ -98,6 +98,8 @@ public class SoundManager { return Sound.ENTITY_ENDER_EYE_DEATH; case GLASS: return Sound.BLOCK_GLASS_BREAK; + case ITEM_CONSUMED: + return Sound.ITEM_BOTTLE_EMPTY; default: return null; } diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java index 3a0e37eda..67e9b0e0b 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java @@ -15,6 +15,7 @@ public enum SoundType { ABILITY_ACTIVATED_BERSERK, BLEED, GLASS, + ITEM_CONSUMED, TIRED; public boolean usesCustomPitch() diff --git a/src/main/resources/sounds.yml b/src/main/resources/sounds.yml index 837559568..f705b7d24 100644 --- a/src/main/resources/sounds.yml +++ b/src/main/resources/sounds.yml @@ -4,6 +4,10 @@ Sounds: # 1.0 = Max volume # 0.0 = No Volume MasterVolume: 1.0 + ITEM_CONSUMED: + Enable: true + Volume: 1.0 + Pitch: 1.0 GLASS: Enable: true Volume: 1.0 From a333f36fd80f3b3425ac41e6d40191fdfe1af048 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 16:19:19 -0800 Subject: [PATCH 40/44] Fix sneak check on GT --- .../com/gmail/nossr50/skills/herbalism/HerbalismManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index c7a91cfc0..0a50a60bf 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -171,7 +171,8 @@ public class HerbalismManager extends SkillManager { //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + if(!getPlayer().isSneaking()) + processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); } //When replanting a immature crop we cancel the block break event and back out @@ -669,7 +670,7 @@ public class HerbalismManager extends SkillManager { * @param greenTerra boolean to determine if greenTerra is active or not */ private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { - if(blockBreakEvent.getPlayer().isSneaking() || !ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { + if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { return; } From a598796c997708c44fef7f5fec7c2e42467af90f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 17:20:05 -0800 Subject: [PATCH 41/44] More tweaks to GT --- Changelog.txt | 2 + .../meta/RecentlyReplantedCropMeta.java | 4 +- .../nossr50/listeners/BlockListener.java | 5 -- .../runnables/skills/DelayedCropReplant.java | 24 ++++--- .../nossr50/skills/herbalism/Herbalism.java | 10 --- .../skills/herbalism/HerbalismManager.java | 65 ++++++++++--------- 6 files changed, 53 insertions(+), 57 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 15d7084df..b3440eba1 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Cocoa plants now require GT of at least 2 to start at the second stage of growth + Green Terra now boosts growth on Green Thumb by 1 stage (doesn't go above the maximum value though) Green Thumb now requires a hoe to activate You can sneak to break plants with a hoe in your hand (or just put the hoe away) Hoes no longer give free replants diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java index 5c630f7bc..20d8e00df 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java @@ -10,8 +10,8 @@ public class RecentlyReplantedCropMeta extends FixedMetadataValue { * * @param owningPlugin the {@link Plugin} that created this metadata value */ - public RecentlyReplantedCropMeta(Plugin owningPlugin) { - super(owningPlugin, true); + public RecentlyReplantedCropMeta(Plugin owningPlugin, Boolean recentlyPlanted) { + super(owningPlugin, recentlyPlanted); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 9023caa3d..56503f3b0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -424,11 +424,6 @@ public class BlockListener implements Listener { BlockState blockState = event.getBlock().getState(); ItemStack heldItem = player.getInventory().getItemInMainHand(); - if (Herbalism.isRecentlyRegrown(blockState)) { - event.setCancelled(true); - return; - } - if (ItemUtils.isSword(heldItem)) { HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager(); diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java index d19411b5e..f00f9579e 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -1,10 +1,12 @@ package com.gmail.nossr50.runnables.skills; +import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.skills.ParticleEffectUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.Ageable; import org.bukkit.event.block.BlockBreakEvent; @@ -37,19 +39,23 @@ public class DelayedCropReplant extends BukkitRunnable { Block cropBlock = cropLocation.getBlock(); BlockState currentState = cropBlock.getState(); + //Remove the metadata marking the block as recently replanted + new markPlantAsOld(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20*5); + if(blockBreakEvent.isCancelled()) { wasImmaturePlant = true; } //Two kinds of air in Minecraft - if(currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { + if(currentState.getType().equals(cropMaterial) || currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { +// if(currentState.getBlock().getRelative(BlockFace.DOWN)) //The space is not currently occupied by a block so we can fill it cropBlock.setType(cropMaterial); //Get new state (necessary?) BlockState newState = cropBlock.getState(); - newState.setType(cropMaterial); - newState.update(); +// newState.update(); + Ageable ageable = (Ageable) newState.getBlockData(); //Crop age should always be 0 if the plant was immature @@ -62,28 +68,30 @@ public class DelayedCropReplant extends BukkitRunnable { //Age the crop newState.setBlockData(ageable); + newState.update(true); //Play an effect ParticleEffectUtils.playGreenThumbEffect(cropLocation); - //Remove the metadata marking the block as recently replanted - new removePlantMeta(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20); } } - private class removePlantMeta extends BukkitRunnable { + private class markPlantAsOld extends BukkitRunnable { private final Location cropLoc; - public removePlantMeta(Location cropLoc) { + public markPlantAsOld(Location cropLoc) { this.cropLoc = cropLoc; } @Override public void run() { Block cropBlock = cropLoc.getBlock(); - cropBlock.removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + if(cropBlock.getMetadata(mcMMO.REPLANT_META_KEY).size() > 0) + cropBlock.setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, false)); + + ParticleEffectUtils.playFluxEffect(cropLocation); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index b486db4f2..e461d2f37 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -58,14 +58,4 @@ public class Herbalism { } } - /** - * Check if the block has a recently grown crop from Green Thumb - * - * @param blockState - * The {@link BlockState} to check green thumb regrown for - * @return true if the block is recently regrown, false otherwise - */ - public static boolean isRecentlyRegrown(BlockState blockState) { - return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1); - } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 0a50a60bf..423778ce0 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -139,6 +139,16 @@ public class HerbalismManager extends SkillManager { return; } + //Check if the plant was recently replanted + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + + return; + } + } + /* * There are single-block plants and multi-block plants in Minecraft * In order to give out proper rewards, we need to collect all blocks that would be broken from this event @@ -161,22 +171,17 @@ public class HerbalismManager extends SkillManager { */ private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet brokenPlants) { BlockState originalBreak = blockBreakEvent.getBlock().getState(); - - //Check if the plant was recently replanted - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { - //Crop is recently replanted to back out of destroying it - blockBreakEvent.setCancelled(true); - return; - } + boolean greenThumbActivated = false; //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - if(!getPlayer().isSneaking()) - processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + if(!getPlayer().isSneaking()) { + greenThumbActivated = processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + } } //When replanting a immature crop we cancel the block break event and back out - if(blockBreakEvent.isCancelled()) { + if(greenThumbActivated) { return; } @@ -659,8 +664,8 @@ public class HerbalismManager extends SkillManager { */ private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) { //Mark the plant as recently replanted to avoid accidental breakage - blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p)); new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge, isImmature).runTaskLater(mcMMO.p, 20 * 2); + blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, true)); } /** @@ -669,15 +674,15 @@ public class HerbalismManager extends SkillManager { * @param blockState The {@link BlockState} to check ability activation for * @param greenTerra boolean to determine if greenTerra is active or not */ - private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + private boolean processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { - return; + return false; } BlockData blockData = blockState.getBlockData(); if (!(blockData instanceof Ageable)) { - return; + return false; } Ageable ageable = (Ageable) blockData; @@ -714,30 +719,30 @@ public class HerbalismManager extends SkillManager { break; default: - return; + return false; } ItemStack seedStack = new ItemStack(seed); if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) { - return; + return false; } if (!playerInventory.containsAtLeast(seedStack, 1)) { - return; + return false; } if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) { - return; + return false; } playerInventory.removeItem(seedStack); player.updateInventory(); // Needed until replacement available //Play sound SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED); - - new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); + return true; +// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) { @@ -747,31 +752,23 @@ public class HerbalismManager extends SkillManager { } int finalAge = 0; - int greenThumbStage = getGreenThumbStage(); + int greenThumbStage = getGreenThumbStage(greenTerra); //Immature plants will start over at 0 if(!isAgeableMature(ageable)) { blockBreakEvent.setCancelled(true); startReplantTask(0, blockBreakEvent, blockState, true); blockState.setType(Material.AIR); - blockState.update(); return true; } - blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); - switch (blockState.getType()) { case POTATOES: case CARROTS: case WHEAT: - if (greenTerra) { - finalAge = 3; - } - else { - finalAge = getGreenThumbStage(); - } + finalAge = getGreenThumbStage(greenTerra); break; case BEETROOTS: @@ -790,7 +787,7 @@ public class HerbalismManager extends SkillManager { case COCOA: - if (greenTerra || getGreenThumbStage() > 1) { + if (getGreenThumbStage(greenTerra) >= 2) { finalAge = 1; } else { @@ -807,7 +804,11 @@ public class HerbalismManager extends SkillManager { return true; } - private int getGreenThumbStage() { + private int getGreenThumbStage(boolean greenTerraActive) { + if(greenTerraActive) + return Math.min(RankUtils.getHighestRank(SubSkillType.HERBALISM_GREEN_THUMB), + RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB) + 1); + return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB); } } From 95c403a467f4ddc1759882b906885f83b79c8526 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 17:31:00 -0800 Subject: [PATCH 42/44] More tweaks to GT --- .../skills/herbalism/HerbalismManager.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 423778ce0..8ff40c286 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -140,12 +140,19 @@ public class HerbalismManager extends SkillManager { } //Check if the plant was recently replanted - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { - //Crop is recently replanted to back out of destroying it - blockBreakEvent.setCancelled(true); + if(blockBreakEvent.getBlock().getBlockData() instanceof Ageable) { + Ageable ageableCrop = (Ageable) blockBreakEvent.getBlock().getBlockData(); - return; + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { + if(isAgeableMature(ageableCrop)) { + blockBreakEvent.getBlock().removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + } else { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + return; + } + } } } @@ -756,9 +763,10 @@ public class HerbalismManager extends SkillManager { //Immature plants will start over at 0 if(!isAgeableMature(ageable)) { - blockBreakEvent.setCancelled(true); +// blockBreakEvent.setCancelled(true); startReplantTask(0, blockBreakEvent, blockState, true); - blockState.setType(Material.AIR); +// blockState.setType(Material.AIR); + blockBreakEvent.setDropItems(false); return true; } From 6168309ec95519989ffe13ca7e08694bf1b45798 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 17:41:47 -0800 Subject: [PATCH 43/44] 2.1.115 --- Changelog.txt | 10 ++++++---- pom.xml | 2 +- .../com/gmail/nossr50/listeners/BlockListener.java | 1 - .../nossr50/runnables/skills/DelayedCropReplant.java | 5 +---- .../com/gmail/nossr50/skills/herbalism/Herbalism.java | 2 -- .../nossr50/skills/herbalism/HerbalismManager.java | 9 ++++++--- src/main/resources/locale/locale_en_US.properties | 2 +- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index b3440eba1..3f896291c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,17 +1,19 @@ Version 2.1.115 + Green Thumb now requires a hoe to activate + Hoes no longer give free replants + You can sneak to break plants with a hoe in your hand (or just put the hoe away) + Using a hoe on non-fully grown crops will replant them as a convenience feature + New sound option in sounds.yml called 'ITEM_CONSUMED', plays when eating seeds for Green Thumb Cocoa plants now require GT of at least 2 to start at the second stage of growth Green Terra now boosts growth on Green Thumb by 1 stage (doesn't go above the maximum value though) - Green Thumb now requires a hoe to activate - You can sneak to break plants with a hoe in your hand (or just put the hoe away) - Hoes no longer give free replants There is now a feature in place to prevent breaking a newly automatically replanted (via green thumb) crop from being breakable for a few seconds after it appears - Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly Fix Axes Critical Strikes default permissions ( new fixed permission: mcmmo.ability.axes.criticalstrikes ) Fix potential null pointer exception for salvage + Updated locale entry 'Herbalism.SubSkill.GreenTerra.Description' Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales diff --git a/pom.xml b/pom.xml index 75680581b..99f42ca84 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.115-SNAPSHOT + 2.1.115 mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 56503f3b0..c73e64f6a 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -14,7 +14,6 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.alchemy.Alchemy; import com.gmail.nossr50.skills.excavation.ExcavationManager; -import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.repair.Repair; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java index f00f9579e..a1ee56320 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -6,7 +6,6 @@ import com.gmail.nossr50.util.skills.ParticleEffectUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.Ageable; import org.bukkit.event.block.BlockBreakEvent; @@ -40,7 +39,7 @@ public class DelayedCropReplant extends BukkitRunnable { BlockState currentState = cropBlock.getState(); //Remove the metadata marking the block as recently replanted - new markPlantAsOld(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20*5); + new markPlantAsOld(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 10); if(blockBreakEvent.isCancelled()) { wasImmaturePlant = true; @@ -90,8 +89,6 @@ public class DelayedCropReplant extends BukkitRunnable { Block cropBlock = cropLoc.getBlock(); if(cropBlock.getMetadata(mcMMO.REPLANT_META_KEY).size() > 0) cropBlock.setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, false)); - - ParticleEffectUtils.playFluxEffect(cropLocation); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index e461d2f37..60166dcdf 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.herbalism; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.skills.SkillUtils; import org.bukkit.Material; import org.bukkit.block.BlockState; diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 8ff40c286..5e668a3db 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -17,7 +17,6 @@ import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.skills.DelayedCropReplant; import com.gmail.nossr50.runnables.skills.DelayedHerbalismXPCheckTask; -import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.*; import com.gmail.nossr50.util.player.NotificationManager; @@ -39,7 +38,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import org.bukkit.metadata.FixedMetadataValue; import java.util.ArrayList; import java.util.Collection; @@ -189,7 +187,12 @@ public class HerbalismManager extends SkillManager { //When replanting a immature crop we cancel the block break event and back out if(greenThumbActivated) { - return; + if(originalBreak.getBlock().getBlockData() instanceof Ageable) { + Ageable ageableCrop = (Ageable) originalBreak.getBlock().getBlockData(); + if(!isAgeableMature(ageableCrop)) { + return; + } + } } /* diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index b2f5b7533..e7457ee53 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -270,7 +270,7 @@ Herbalism.Ability.Lower=[[GRAY]]You lower your Hoe. Herbalism.Ability.Ready=[[DARK_AQUA]]You [[GOLD]]ready[[DARK_AQUA]] your Hoe. Herbalism.Ability.ShroomThumb.Fail=**SHROOM THUMB FAIL** Herbalism.SubSkill.GreenTerra.Name=Green Terra -Herbalism.SubSkill.GreenTerra.Description=Spread the Terra, 3x Drops +Herbalism.SubSkill.GreenTerra.Description=Spread the Terra, 3x Drops, Boosts Green Thumb Herbalism.SubSkill.GreenTerra.Stat=Green Terra Duration Herbalism.SubSkill.GreenThumb.Name=Green Thumb Herbalism.SubSkill.GreenThumb.Description=Auto-Plants crops when harvesting From 4e895b7361a4d8408266a78e1d6f064a7b8ff5f7 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 20 Feb 2020 15:23:58 -0800 Subject: [PATCH 44/44] Some kyori/text stuff --- .../commands/admin/NBTToolsCommand.java | 29 ++++- .../gmail/nossr50/locale/LocaleManager.java | 2 +- .../main/java/com/gmail/nossr50/mcMMO.java | 1 + .../com/gmail/nossr50/text/TextManager.java | 106 ++++++++++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/text/TextManager.java 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 index 1b16e9e2e..5db9e8d1e 100644 --- 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 @@ -3,6 +3,11 @@ package com.gmail.nossr50.commands.admin; import co.aikar.commands.BaseCommand; import co.aikar.commands.annotation.*; import com.gmail.nossr50.mcMMO; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import net.kyori.text.TextComponent; +import net.kyori.text.adapter.bukkit.TextAdapter; +import net.kyori.text.format.TextColor; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -15,15 +20,33 @@ public class NBTToolsCommand extends BaseCommand { private mcMMO plugin; @Default + @CommandPermission("mcmmo.commands.nbttools") public void onCommand(Player player) { + //TODO: Add some help messages player.sendMessage("hi"); } /** * Show the NBT tags of an item in hand */ - @Subcommand("showtags") + @Subcommand("tags show") public void onShowTags(Player player) { + final TextComponent textComponent = TextComponent.builder() + .content(plugin.getLocaleManager().getString("mcMMO.Template.Prefix")) + .append("NBT Tools") + .color(TextColor.GOLD) + .append(" - ") + .append("Showing NBT Tags (") + .append(player.getInventory().getItemInMainHand().getType().getKey().toString()) + .color(TextColor.GREEN) + .append(")") + .color(TextColor.GOLD) + .append(TextComponent.newline()) + .build(); + + String json = GsonComponentSerializer.INSTANCE.serialize(textComponent); + TextAdapter.sendMessage(player, textComponent); + //Show NBT tags to player player.sendMessage(STYLE_TEXT_1 + " NBT TOOLS " + STYLE_TEXT_1); player.sendMessage("NBT Analysis: " + player.getInventory().getItemInMainHand().getType().getKey().toString()); @@ -32,12 +55,12 @@ public class NBTToolsCommand extends BaseCommand { player.sendMessage(ChatColor.GRAY + "NBT Analysis completed!"); } - @Subcommand("add") + @Subcommand("tags add") public void onAddTags(Player player) { } - @Subcommand("remove") + @Subcommand("tags remove") public void onRemoveTags(Player player) { } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/locale/LocaleManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/locale/LocaleManager.java index 6b93cc074..aeec612ce 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/locale/LocaleManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/locale/LocaleManager.java @@ -124,7 +124,7 @@ public final class LocaleManager { } } - private static String addColors(String input) { + public static String addColors(String input) { input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString()); input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString()); input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.toString()); 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 64f0d801f..e03febf7b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -47,6 +47,7 @@ import com.gmail.nossr50.util.skills.SkillTools; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; +import net.kyori.text.adapter.bukkit.TextAdapter; import net.shatteredlands.shatt.backup.ZipLibrary; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/text/TextManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/text/TextManager.java new file mode 100644 index 000000000..cc51662e3 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/text/TextManager.java @@ -0,0 +1,106 @@ +package com.gmail.nossr50.text; + +import com.gmail.nossr50.mcMMO; +import net.kyori.text.TextComponent; +import net.kyori.text.adapter.bukkit.TextAdapter; +import net.kyori.text.serializer.gson.GsonComponentSerializer; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Handles some boiler plate related to kyori powered text library + */ +public class TextManager { + public static final char COLOR_CHAR = 'ยง'; + private mcMMO pluginRef; + + public TextManager(mcMMO pluginRef) { + this.pluginRef = pluginRef; + } + + /** + * Send a message to multiple recipients + * @param commandSenders target recipients + * @param textComponent the {@link TextComponent} to send + */ + public void sendMessage(List commandSenders, TextComponent textComponent) { + for(CommandSender commandSender : commandSenders) { + sendMessage(commandSender, textComponent); + } + } + + /** + * Serializes and sends a text message to a specific recipient + * @param commandSender target recipient + * @param textComponent the {@link TextComponent} to serialize and send + */ + public void sendMessage(CommandSender commandSender, TextComponent textComponent) { + String json = GsonComponentSerializer.INSTANCE.serialize(textComponent); + TextAdapter.sendMessage(commandSender, textComponent); + } + + /** + * Sends a message to a single recipient with the (mcMMO) watermark at the beginning of the message + * @param commandSender target recipient + * @param textComponent the {@link TextComponent} to watermark and send + */ + public void sendMessageWatermarked(CommandSender commandSender, TextComponent textComponent) { + TextComponent waterMarkedComponent = buildWaterMarked(textComponent); + + sendMessage(commandSender, waterMarkedComponent); + } + + /** + * Sends a message to a list of recipients with the (mcMMO) watermark at the beginning of the message + * @param commandSenders target recipients + * @param textComponent the {@link TextComponent} to watermark and send + */ + public void sendMessageWatermarked(List commandSenders, TextComponent textComponent) { + TextComponent waterMarkedComponent = buildWaterMarked(textComponent); + + for(CommandSender commandSender : commandSenders) { + sendMessage(commandSender, waterMarkedComponent); + } + } + + /** + * Builds a watermarked version of a text component + * @param textComponent target component to watermark + * @return a new {@link TextComponent} with the (mcMMO) watermark at the beginning and the contents of {@link TextComponent} appended afterwards + */ + @NotNull + private TextComponent buildWaterMarked(TextComponent textComponent) { + return TextComponent.builder().content(pluginRef.getLocaleManager().getString("mcMMO.Template.Prefix")).append(textComponent).build(); + } + + /** + * Dissects a string and builds a {@link TextComponent} out of it. + * Results are cached to avoid needless operations in the future + * @param legacyText target text to transform + */ + private TextComponent transformLegacyTexts(String legacyText) { + //TODO: Cache results + TextComponent.Builder builder = TextComponent.builder(); + + for(int i = 0; i < legacyText.toCharArray().length; i++) { + char c = legacyText.charAt(i); + + //Found color character + if(c == COLOR_CHAR) { + if(i+1 >= legacyText.toCharArray().length) { + //No color code because we're at the end of the string + builder.append(String.valueOf(c)); + } else { + //TODO: finish + } + } else { + //Not a color character + } + } + return builder.build(); + } + +}