[Util][1.6.2]Editing Item Attributes - No Externals!

Discussion in 'Resources' started by kreashenz, Jul 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    kreashenz

    Hello Bukkit, and welcome to a thread that I have made, that shows you how to remove item attributes. Very simple and very easy, with only 1 extra class file you need, with no external plugins/libraries! Even better, none if it needs to get updated, just yet! This couldn't have been done without stirante and his wonderful work, as he wrote all the classes, I just turned them into the thread, with his permission of course, you should all thank him!

    Warning: This is only to REMOVE/ADD attributes, not hide them (just yet)!

    Yes, I do know there was a thread created by @Comprenix that does the same thing, but his, without ProtocolLib, would need updating every update, it's why I made this thread. Sorry if this makes you sad @Comprenix !

    Examples on how to use each of them:
    Adding attributes:
    I am not too sure on how to add them, but hopefully someone can give me a

    Removing attributes:
    Code:java
    1. ItemStack dAxe = new ItemStack(Material.DIAMOND_AXE, 1);
    2. AttributeAPI.removeAttribute(dAxe);


    Removing potion attributes:
    Code:java
    1. ItemStack slowPot = new ItemStack(Material.POTION, 1, (short)8266);
    2. AttributeAPI.removeAttributePotion(slowPot);


    Well, here's how to do it, but first of all, you're going to need to edit your reflection class and if you don't have one, well, here's one for you!
    Code:java
    1. package ;
    2.  
    3. import java.lang.reflect.Field;
    4. import java.lang.reflect.Method;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.inventory.ItemStack;
    8.  
    9. public class NMSStuff {
    10.  
    11. public static Class<?> getNMSClass(String clazz){
    12. try {
    13. return Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "." + clazz);
    14. }
    15. catch (Throwable t){
    16. t.printStackTrace();
    17. }
    18. return null;
    19. }
    20.  
    21. public static Class<?> getCBClass(String clazz){
    22. try {
    23. return Class.forName("org.bukkit.craftbukkit." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "." + clazz);
    24. }
    25. catch (Throwable t){
    26. t.printStackTrace();
    27. }
    28. return null;
    29. }
    30.  
    31. public static Object getNMSValue(String clazz, String field, Object object){
    32. try {
    33. Field f = getNMSClass(clazz).getDeclaredField(field);
    34. f.setAccessible(true);
    35. return f.get(object);
    36. }
    37. catch (Throwable t){
    38. t.printStackTrace();
    39. }
    40. return null;
    41. }
    42.  
    43. public static void setNMSValue(String clazz, String field, Object object, Object value){
    44. try {
    45. Field f = getNMSClass(clazz).getDeclaredField(field);
    46. f.setAccessible(true);
    47. f.set(object, value);
    48. }
    49. catch (Throwable t){
    50. t.printStackTrace();
    51. }
    52. }
    53.  
    54. public static Object getCBValue(String clazz, String field, Object object){
    55. try {
    56. Field f = getCBClass(clazz).getDeclaredField(field);
    57. f.setAccessible(true);
    58. return f.get(object);
    59. }
    60. catch (Throwable t){
    61. t.printStackTrace();
    62. }
    63. return null;
    64. }
    65.  
    66. public static void setCBValue(String clazz, String field, Object object, Object value){
    67. try {
    68. Field f = getCBClass(clazz).getDeclaredField(field);
    69. f.setAccessible(true);
    70. f.set(object, value);
    71. }
    72. catch (Throwable t){
    73. t.printStackTrace();
    74. }
    75. }
    76.  
    77. public static Object getNMSItem(ItemStack item){
    78. try {
    79. Method meth = getCBClass("inventory.CraftItemStack").getDeclaredMethod("asNMSCopy", ItemStack.class);
    80. return meth.invoke(null, item);
    81. }
    82. catch (Throwable t){
    83. t.printStackTrace();
    84. }
    85. return null;
    86. }
    87.  
    88. public static ItemStack getBukkitItem(Object item){
    89. try {
    90. Method meth = getCBClass("inventory.CraftItemStack").getDeclaredMethod("asCraftMirror", getNMSClass("ItemStack"));
    91. return (ItemStack)meth.invoke(null, item);
    92. }
    93. catch (Throwable t){
    94. t.printStackTrace();
    95. }
    96. return null;
    97. }
    98.  
    99. }


    This is to get the NMS/OCB things used for this to happen.

    Second, you're going to need the methods to add/edit/remove them. I will name each one above the codes, so make sure you know which ones you're wanting!

    Adding attributes :
    Code:java
    1. public static ItemStack addAttribute(ItemStack item, Attributes attribute, double value, Operation op) {
    2. try {
    3. Object nmsItem = NMSStuff.getNMSItem(item);
    4. Object tag1 = createModifierTag(attribute, value, op);
    5. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    6. if (tag == null) {
    7. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    8. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    9. }
    10. Object modifiers = NMSStuff.getNMSClass("NBTTagCompound").getMethod("get", String.class).invoke(tag, "AttributeModifiers");
    11. if (modifiers == null)
    12. modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    13. NMSStuff.getNMSClass("NBTTagList").getDeclaredMethod("add", NMSStuff.getNMSClass("NBTBase")).invoke(modifiers, tag1);
    14. NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase")).invoke(tag, "AttributeModifiers", modifiers);
    15. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    16. return NMSStuff.getBukkitItem(nmsItem);
    17. }
    18. catch (Throwable t) {
    19. t.printStackTrace();
    20. }
    21. return item;
    22. }


    Removing item attributes excluding potions
    Code:java
    1. public static ItemStack removeAttributes(ItemStack item){
    2. try {
    3. Object nmsItem = NMSStuff.getNMSItem(item);
    4. Object modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    5. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    6. if (tag == null) {
    7. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    8. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    9. }
    10. Method meth = NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase"));
    11. meth.invoke(tag, "AttributeModifiers", modifiers);
    12. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    13. return NMSStuff.getBukkitItem(nmsItem);
    14. }
    15. catch (Throwable t) {
    16. t.printStackTrace();
    17. }
    18. return item;
    19. }


    Removing item attributes including potions
    Code:java
    1. public static ItemStack removeAttributesPotion(ItemStack item){
    2. try {
    3. Object nmsItem = NMSStuff.getNMSItem(item);
    4. Object modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    5. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    6. if (tag == null) {
    7. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    8. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    9. }
    10. Method meth = NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase"));
    11. meth.invoke(tag, "CustomPotionEffects", modifiers);
    12. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    13. return NMSStuff.getBukkitItem(nmsItem);
    14. }
    15. catch (Throwable t) {
    16. t.printStackTrace();
    17. }
    18. return item;
    19. }


    They're mainly it. The NMSStuff class is above, and if you want, of course you can rename it!

    There's still some other classes you might need.
    Attributes enum (open)
    This is the attributes enum that is called in the first 2 methods. Private because they should (but don't have to be) be nested.
    Code:java
    1. private enum Attributes {
    2.  
    3. SPAWN_REINFORCEMENTS(NMSStuff.getNMSValue("EntityZombie", "bp", null)),
    4. JUMP_STRENGTH(NMSStuff.getNMSValue("EntityHorse", "bv", null)),
    5. MAX_HEALTH(NMSStuff.getNMSValue("GenericAttributes", "a", null)),
    6. FOLLOW_RANGE(NMSStuff.getNMSValue("GenericAttributes", "b", null)),
    7. KNOCKBACK_RESISTANCE(NMSStuff.getNMSValue("GenericAttributes", "c", null)),
    8. MOVEMENT_SPEED(NMSStuff.getNMSValue("GenericAttributes", "d", null)),
    9. ATTACK_DAMAGE(NMSStuff.getNMSValue("GenericAttributes", "e", null));
    10.  
    11. private Object attribute;
    12.  
    13. private Attributes(Object a){
    14. attribute = a;
    15. }
    16.  
    17. public String getAttributeName(){
    18. try {
    19. return (String) NMSStuff.getNMSClass("AttributeBase").getMethod("a").invoke(attribute);
    20. }
    21. catch (Throwable t) {
    22. t.printStackTrace();
    23. }
    24. return null;
    25. }
    26.  
    27. public double getDefaultValue(){
    28. try {
    29. return (Double)NMSStuff.getNMSClass("AttributeBase").getMethod("b").invoke(attribute);
    30. }
    31. catch (Throwable t) {
    32. t.printStackTrace();
    33. }
    34. return 0;
    35. }
    36.  
    37. public double getFixedValue(double value){
    38.  
    39. try {
    40. return (Double)NMSStuff.getNMSClass("AttributeRanged").getMethod("a", Double.class).invoke(attribute, value);
    41. }
    42. catch (Throwable t) {
    43. t.printStackTrace();
    44. }
    45. return 0;
    46. }
    47.  
    48. public Object getAttributeInstance(){
    49. return attribute;
    50. }
    51. }


    Operations enum (open)
    This is also used in the first 2 methods. Private because they should be (but don't have to be) nested.
    Code:java
    1. private enum Operation {
    2.  
    3. ADD_AMOUNT(0),
    4. ADDITIVE_PERCENTAGE(1),
    5. MULTIPLICATIVE_PERCENTAGE(2);
    6.  
    7. private int i;
    8.  
    9. private Operation(int i){
    10. this.i = i;
    11. }
    12.  
    13. public int getValue() {
    14. return i;
    15. }
    16.  
    17. }


    Here's the whole class in case you don't care about reading the way above.
    Whole Class (open)
    Code:java
    1. package ;
    2.  
    3. import java.lang.reflect.Method;
    4. import java.util.UUID;
    5.  
    6. import org.bukkit.inventory.ItemStack;
    7.  
    8. public class AttributeAPI {
    9.  
    10. public static ItemStack addAttribute(ItemStack item, Attributes attribute, double value, Operation op) {
    11. try {
    12. Object nmsItem = NMSStuff.getNMSItem(item);
    13. Object tag1 = createModifierTag(attribute, value, op);
    14. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    15. if (tag == null) {
    16. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    17. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    18. }
    19. Object modifiers = NMSStuff.getNMSClass("NBTTagCompound").getMethod("get", String.class).invoke(tag, "AttributeModifiers");
    20. if (modifiers == null)
    21. modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    22. NMSStuff.getNMSClass("NBTTagList").getDeclaredMethod("add", NMSStuff.getNMSClass("NBTBase")).invoke(modifiers, tag1);
    23. NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase")).invoke(tag, "AttributeModifiers", modifiers);
    24. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    25. return NMSStuff.getBukkitItem(nmsItem);
    26. }
    27. catch (Throwable t) {
    28. t.printStackTrace();
    29. }
    30. return item;
    31. }
    32.  
    33. private static Object createModifierTag(Attributes attribute, double value, Operation op) throws Throwable {
    34. Class<?> compound = NMSStuff.getNMSClass("NBTTagCompound");
    35. Method setString = compound.getDeclaredMethod("setString", String.class, String.class);
    36. Method setLong = compound.getDeclaredMethod("setString", String.class, long.class);
    37. Method setInt = compound.getDeclaredMethod("setString", String.class, int.class);
    38. UUID uid = UUID.randomUUID();
    39. Object tag = compound.newInstance();
    40. setString.invoke(tag, "AttributeName", attribute.getAttributeName());
    41. setString.invoke(tag, "Name", attribute.getAttributeName());
    42. setString.invoke(tag, "Amount", value);
    43. setInt.invoke(tag, "Operation", op.getValue());
    44. setLong.invoke(tag, "UUIDMost", uid.getMostSignificantBits());
    45. setLong.invoke(tag, "UUIDLeast", uid.getLeastSignificantBits());
    46. return tag;
    47. }
    48.  
    49.  
    50. public static ItemStack removeAttributes(ItemStack item){
    51. try {
    52. Object nmsItem = NMSStuff.getNMSItem(item);
    53. Object modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    54. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    55. if (tag == null) {
    56. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    57. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    58. }
    59. Method meth = NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase"));
    60. meth.invoke(tag, "AttributeModifiers", modifiers);
    61. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    62. return NMSStuff.getBukkitItem(nmsItem);
    63. }
    64. catch (Throwable t) {
    65. t.printStackTrace();
    66. }
    67. return item;
    68. }
    69.  
    70. public static ItemStack removeAttributesPotion(ItemStack item){
    71. try {
    72. Object nmsItem = NMSStuff.getNMSItem(item);
    73. Object modifiers = NMSStuff.getNMSClass("NBTTagList").newInstance();
    74. Object tag = NMSStuff.getNMSValue("ItemStack", "tag", nmsItem);
    75. if (tag == null) {
    76. tag = NMSStuff.getNMSClass("NBTTagCompound").newInstance();
    77. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    78. }
    79. Method meth = NMSStuff.getNMSClass("NBTTagCompound").getDeclaredMethod("set", String.class, NMSStuff.getNMSClass("NBTBase"));
    80. meth.invoke(tag, "CustomPotionEffects", modifiers);
    81. NMSStuff.setNMSValue("ItemStack", "tag", nmsItem, tag);
    82. return NMSStuff.getBukkitItem(nmsItem);
    83. }
    84. catch (Throwable t) {
    85. t.printStackTrace();
    86. }
    87. return item;
    88. }
    89.  
    90. private enum Attributes {
    91.  
    92. SPAWN_REINFORCEMENTS(NMSStuff.getNMSValue("EntityZombie", "bp", null)),
    93. JUMP_STRENGTH(NMSStuff.getNMSValue("EntityHorse", "bv", null)),
    94. MAX_HEALTH(NMSStuff.getNMSValue("GenericAttributes", "a", null)),
    95. FOLLOW_RANGE(NMSStuff.getNMSValue("GenericAttributes", "b", null)),
    96. KNOCKBACK_RESISTANCE(NMSStuff.getNMSValue("GenericAttributes", "c", null)),
    97. MOVEMENT_SPEED(NMSStuff.getNMSValue("GenericAttributes", "d", null)),
    98. ATTACK_DAMAGE(NMSStuff.getNMSValue("GenericAttributes", "e", null));
    99.  
    100. private Object attribute;
    101.  
    102. private Attributes(Object a){
    103. attribute = a;
    104. }
    105.  
    106. public String getAttributeName(){
    107. try {
    108. return (String) NMSStuff.getNMSClass("AttributeBase").getMethod("a").invoke(attribute);
    109. }
    110. catch (Throwable t) {
    111. t.printStackTrace();
    112. }
    113. return null;
    114. }
    115.  
    116. public double getDefaultValue(){
    117. try {
    118. return (Double)NMSStuff.getNMSClass("AttributeBase").getMethod("b").invoke(attribute);
    119. }
    120. catch (Throwable t) {
    121. t.printStackTrace();
    122. }
    123. return 0;
    124. }
    125.  
    126. public double getFixedValue(double value){
    127.  
    128. try {
    129. return (Double)NMSStuff.getNMSClass("AttributeRanged").getMethod("a", Double.class).invoke(attribute, value);
    130. }
    131. catch (Throwable t) {
    132. t.printStackTrace();
    133. }
    134. return 0;
    135. }
    136.  
    137. public Object getAttributeInstance(){
    138. return attribute;
    139. }
    140. }
    141.  
    142. private enum Operation {
    143.  
    144. ADD_AMOUNT(0),
    145. ADDITIVE_PERCENTAGE(1),
    146. MULTIPLICATIVE_PERCENTAGE(2);
    147.  
    148. private int i;
    149.  
    150. private Operation(int i){
    151. this.i = i;
    152. }
    153.  
    154. public int getValue() {
    155. return i;
    156. }
    157.  
    158. }
    159.  
    160. }


    That's it so far, everyone, thanks for reading and I hope you enjoy all of this! As I said above, couldn't have been done without stirante, so please again, thank him!

    (Because I don't want to have to re-format it all over again, sorry I had to double post) This cannot be used in creative, or else the items will reset the attributes. This is also very good for Item Menus, and things you do not want to do damage. When stirante is ready, I will also add adding attributes, and how to do that, and then maybe even hiding attributes, so you don't have a diamond sword doing the same damage as a stick!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    shmkane

    Very nice post! It's nice to know its possible to do this without ProtocalLib. I'll have to try this out sometime!
     
  3. Offline

    kreashenz

    CaptainBern Yeah, stirante told me, I didn't want to edit it because I'd have to reformat it, so.. Lol. Thanks for that, anyway :)
     
  4. Offline

    ELCHILEN0

    kreashenz To get around the formatting issues with the code tags you can copy the contents of your post then switch into the plain text editor mode, paste then add re-add the tags to surround the code blocks! ;)
     
  5. Offline

    metalhedd

    kreashenz
    None of this code worked for me. I was using this code to test:

    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            ItemStack head = new ItemStack(Material.IRON_HELMET);
           
     
            AttributeAPI.addAttribute(head, AttributeAPI.Attributes.MOVEMENT_SPEED, -10, AttributeAPI.Operation.ADDITIVE_PERCENTAGE);
           
            event.getPlayer().getInventory().addItem(head);
           
        }
    this should give me helmet that applies -10% movement speed, if I understand correctly.

    first, AttributesAPI.createModifierTag has several issues.
    Code:java
    1. private static Object createModifierTag(Attributes attribute, double value, Operation op) throws Throwable {
    2. Class<?> compound = NMSStuff.getNMSClass("NBTTagCompound");
    3. Method setString = compound.getDeclaredMethod("setString", String.class, String.class);
    4. Method setLong = compound.getDeclaredMethod("setString", String.class, long.class); // ERROR, no such method.
    5. Method setInt = compound.getDeclaredMethod("setString", String.class, int.class); // ERROR, No such method
    6. UUID uid = UUID.randomUUID();
    7. Object tag = compound.newInstance();
    8. setString.invoke(tag, "AttributeName", attribute.getAttributeName());
    9. setString.invoke(tag, "Name", attribute.getAttributeName());
    10. setString.invoke(tag, "Amount", value); // Argument type mismatch.
    11. setInt.invoke(tag, "Operation", op.getValue());
    12. setLong.invoke(tag, "UUIDMost", uid.getMostSignificantBits());
    13. setLong.invoke(tag, "UUIDLeast", uid.getLeastSignificantBits());
    14. return tag;
    15. }
    16.  


    the first 2 are apparently typos. the 3rd one I wasn't sure if I should be calling a different method, or casting the double to a string, I went with the latter.

    next you get this beauty:
    Code:
    18:47:51 [SEVERE] java.lang.NoSuchFieldException: bv
    18:47:51 [SEVERE]    at java.lang.Class.getDeclaredField(Class.java:1938)
    18:47:51 [SEVERE]    at com.norcode.bukkit.attrs.NMSStuff.getNMSValue(NMSStuff.java:33)
    18:47:51 [SEVERE]    at com.norcode.bukkit.attrs.AttributeAPI$Attributes.<clinit>(AttributeAPI.java:93)
    
    this refers to:
    JUMP_STRENGTH(NMSStuff.getNMSValue("EntityHorse", "bv", null)),
    I checked EntityHorse, bv is a public method, not a field. so that's why this fails. Im not sure what it's supposed to refer to, but I just removed the JUMP_STRENGTH as I didn't need it.
    So, now it all compiles and runs without error, and I get my helmet, and ... nothing. it has no visible attributes, nor does it appear to slow me down at all. next step for me is to peer into the nbt tags with an external editor and see if there's some obvious typo, I guess.
     
  6. Offline

    Comphenix

    Albeit very powerful, reflection does come with a performance and stability cost. It can be difficult to read and write, is quite a bit slower (how depends on the situation), and much more prone to typos than normal statically checked code. Kind of like skipping Option Explicit in VB, except worse.

    Don't get me wrong, I do think this price may be worth to pay. I wrote a whole library around it. But, you should keep it in mind when you choose a version that uses reflection above one that doesn't. The performance issue probably doesn't matter on modern hardware (to a degree), but the stability does. So, I wrote my attribute API without reflection, along with a version that does, but it abstracts it all away in a library. And the ProtocolLib version does work in 1.6.2.

    Unfortunately, reflection is not a magic solution to stay version independent. Accessing fields by their obfuscated name, such as 'bp' and 'bv' is just asking for trouble - these values may vary between each release, and easily crash in future versions; worse, they may refer to a different field with the same type, and do the completely wrong thing. In fact, you might as well skipped reflection altogether for all the extra compatibility you get. The only benefit is that you don't have to depend on CraftBukkit in Eclipse.

    In PL, I usually refer to fields by their type and order in the source code, though that's still not a perfect solution (Searge/MCP translation tables?). Your best bet is usually to write backwards compatible code, and explicitly crash on new unknown versions. But of course, that's too inconvenient for most people.

    In any case, we'll probably see an official API for attributes implemented soon (â„¢), so I doubt all this future compatibility is necessary.

    This is probably because you're in creative mode, and older versions of CraftBukkit will clear all unknown NBT tags such as the new attributes. Try using the latest development build of CraftBukkit instead, where this was fixed (1) (2).
     
  7. Offline

    metalhedd


    Thanks for the info, I actually found your library shortly after posting this, and it worked perfectly after a quick port to 1.6.2

    I was using the latest development build when I tested this, I redownloaded it fresh this afternoon to properly document my trials here. I also was aware of the creative mode issues so I made sure I was in survival all along, there was something else wrong that I couldn't be bothered to debug further. Let that be a lesson to me for copying code from a forum post, never before, never again, it must at least be a gist. :D
     
  8. Offline

    Comphenix

    No problem. :)

    Sure, though the absolute latest version as I write this (#2822) finally corrects the creative mode issue.

    It's certainly easier to copy, and much easier for whoever posted it to update. I much prefer the <<code>> tag on BukkitDev or using Gist than the [syntax) tag on the forums.
     
  9. Offline

    metalhedd

    I fired it up again just to double check:

    21:46:17 [INFO] This server is running CraftBukkit version git-Bukkit-1.5.2-R1.0-34-gafd618a-b2822jnks (MC: 1.6.2) (Implementing API version 1.6.2-R0.1-SNAPSHOT)

    I deleted my modified version of the OP's code already, otherwise I would try again just to confirm, but, it's been replaced with the functional version from you, thanks again.
     
  10. Offline

    ainast

    I'm having a bit of an issue, think you could help me out? Thanks.

    Code:java
    1. Caused by: java.lang.NoClassDefFoundError: com/comphenix/protocol/wrappers/nbt/NbtBase
    2. at com.ainast.morepowerfulmobs.MorePowerfulMobs.regionHarderMob2(MorePowerfulMobs.java:141)
    3. at com.ainast.morepowerfulmobs.MorePowerfulMobs.creatureSpawnEvent(MorePowerfulMobs.java:102)
    4. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    5. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    6. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    7. at java.lang.reflect.Method.invoke(Method.java:597)
    8. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    9. ... 21 more
    10. Caused by: java.lang.ClassNotFoundException: com.comphenix.protocol.wrappers.nbt.NbtBase
    11. at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    12. at java.security.AccessController.doPrivileged(Native Method)
    13. at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    14. at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
    15. at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
    16. at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    17. at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    18.  
     
  11. Offline

    kreashenz

    ainast You're importing ProtocolLib's NBTBase class, not NMS's.
     
  12. Offline

    ainast

    Ah, as my elementary school teacher always said, "Reads and Follows Directions."

    Thanks man.

    I'm having one more error, I figure I'll ask just in case I can't solve it by tomorrow.

    Code:
    23:48:51 [SEVERE] java.lang.NoSuchMethodException: net.minecraft.server.v1_6_R2.NBTTagCompound.setString(java.lang.String, long)
    23:48:51 [SEVERE]    at java.lang.Class.getDeclaredMethod(Class.java:1964)
    23:48:51 [SEVERE]    at com.ainast.morepowerfulmobs.AttributeAPI.createModifierTag(AttributeAPI.java:36)
    23:48:51 [SEVERE]    at com.ainast.morepowerfulmobs.AttributeAPI.addAttribute(AttributeAPI.java:13)
    23:48:51 [SEVERE]    at com.ainast.morepowerfulmobs.MorePowerfulMobs.regionHarderMob2(MorePowerfulMobs.java:140)
    23:48:51 [SEVERE]    at com.ainast.morepowerfulmobs.MorePowerfulMobs.creatureSpawnEvent(MorePowerfulMobs.java:100)
    23:48:51 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    23:48:51 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    23:48:51 [SEVERE]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    23:48:51 [SEVERE]    at java.lang.reflect.Method.invoke(Method.java:597)
    23:48:51 [SEVERE]    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    23:48:51 [SEVERE]    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    23:48:51 [SEVERE]    at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    23:48:51 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
    23:48:51 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
    23:48:51 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callCreatureSpawnEvent(CraftEventFactory.java:256)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.World.addEntity(World.java:974)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.ItemMonsterEgg.a(ItemMonsterEgg.java:110)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.ItemMonsterEgg.interactWith(ItemMonsterEgg.java:37)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.ItemStack.placeItem(ItemStack.java:79)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.PlayerInteractManager.interact(PlayerInteractManager.java:390)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:628)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
    23:48:51 [SEVERE]    at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:230)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    23:48:51 [SEVERE]    at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:125)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:592)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
    23:48:51 [SEVERE]    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    
    I actually, just reread the topic above and changed the typos in the method and other things. It runs fine, but doesn't add or at least show the attribute on the item. Any advice?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  13. Offline

    kreashenz

    ainast [EDIT] My post didn't update. I am not sure why the tag isn't showing.
     
  14. Offline

    ainast

    but does that mean the effect is still there? I could prob. just update the lore myself to include the message.
     
  15. Offline

    kreashenz

    ainast It might. I've honestly never used it in any of my plugins, maybe stirante has. I only remove the Attributes for inventory GUIs. Sorry I'm not of much help, here.
     
  16. Offline

    stirante

    kreashenz ainast Removing and adding is just adding and removing so if you delete attributes from sword you will deal same damage as any item.
     
  17. Offline

    ainast

    ah, I think I was adding the properly, but idk. Hopefully we will get attributes support soon.
     
  18. Offline

    DoctorDark

    kreashenz Will you be updating this? Doesn't seem to be compatible for 1.7 :/
     
  19. Offline

    kreashenz

    DoctorDark Because of problems in life, I'm going to have no PC for over a month. There may be others who could update this maybe stirante .
     
  20. Offline

    Comphenix

    You can use my attribute library in 1.7.2.
     
  21. Offline

    DoctorDark

    Comphenix
    Would this method also remove the "Instant Health II" tag, as I couldn't seem to find a viable way.
     
  22. Offline

    Comphenix

    No, that's all client side.

    But you could rename a water bottle to "Potion of Health", and use Bukkit events to recreate the health effect. Unfortunately, the potion would not have the correct color, but at least it wouldn't have the effect description.
     
  23. Offline

    Qwahchees

    Hey, I just tried to use this and no dice. The +3 Damage still shows, not sure what else I can do. I've tried a few sources to fix this.
     
Thread Status:
Not open for further replies.

Share This Page