How to make all items unbreakable?

Discussion in 'General Help' started by HardMCore, Jan 11, 2018.

Thread Status:
Not open for further replies.
  1. As in the title. Im trying to create plugin that will make items unbreakable, but I dont know how. It would be nice if all items could be unbreakable. My plugin code:
    Code:
    package me.HardMCore;
    
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import net.minecraft.server.v1_8_R1.ItemStack;
    import net.minecraft.server.v1_8_R1.NBTTagCompound;
    
    
    public class EVENT_PlayerRespawn implements Listener{
       
        @EventHandler
        public void onRespawn(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
           
            ItemStack sword = new ItemStack (Material.STONE_SWORD);
           
            ItemStack helmet = new ItemStack(Material.LEATHER_HELMET, 1);
            ItemStack chest = new ItemStack (Material.LEATHER_CHESTPLATE);
            ItemStack leggings = new ItemStack (Material.LEATHER_LEGGINGS);
            ItemStack boots = new ItemStack (Material.LEATHER_BOOTS);
           
            setUnbreakable(sword);
            setUnbreakable(helmet);
            setUnbreakable(chest);
            setUnbreakable(leggings);
            setUnbreakable(boots);
           
            p.getInventory().addItem(sword);
            p.getInventory().addItem(helmet);
            p.getInventory().addItem(chest);
            p.getInventory().addItem(leggings);
            p.getInventory().addItem(boots);
        }
        private void setUnbreakable(ItemStack item) {
            net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack setTag(tag);
        }
    }
    Errors:

    The constructor ItemStack(Material) is undefined

    The method addItem(ItemStack...) in the type Inventory is not applicable for the arguments (ItemStack)

    The method asNMSCopy(org.bukkit.inventory.ItemStack) in the type CraftItemStack is not applicable for the arguments
    (net.minecraft.server.v1_8_R1.ItemStack)

    I dont know why I have these errors. I just copied 1:1 code from a youtuber and only one difference is version,I have net.minecraft.server.v1_8_R1, but he had net.minecraft.server.v1_8_R3.

    What should I do?
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Soo, what's the right ItemStack? Im beginner and I wanted to learn from copy-writing as I did it with Pawn. And I also wanted to create unbreakable items plugin for my server. Can you explain what means "You imported the wrong ItemStack" please?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @HardMCore You only have 1 ItemStack import.
    Remove that line, your editor will complain, import the one without the version numbers.
     
  5. Okay, thanks! I changed it, there are no errors, but I cant load the plugin. Console shows another error:

    Code:
     Could not load 'plugins\NoItemDamage.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: main class `me.HardMCore.EVENT_PlayerRespawn' does not extend JavaPlugin
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:73) ~[craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:152) [craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
    Caused by: java.lang.ClassCastException: class me.HardMCore.EVENT_PlayerRespawn
            at java.lang.Class.asSubclass(Unknown Source) ~[?:1.8.0_151]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:71) ~[craftbukkit.jar:git-Spigot-c3c767f-33d5de3]
            ... 7 more
     
  6. Offline

    timtower Administrator Administrator Moderator

    @HardMCore Your main class should extend JavaPlugin, you don't have that now.
     
  7. okay, so I ended the plugin, but it doesnt work. Items aren't unbreakable. Why? What to do? Is it code problem? Console doesnt show any errors.
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Code:
    package me.hardmcore.in;
    
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_8_R1.NBTTagCompound;
    
    
    public class Main extends JavaPlugin implements Listener{
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            ItemStack sword = new ItemStack (Material.WOOD_SWORD);
            ItemStack sword1 = new ItemStack (Material.GOLD_SWORD);
            ItemStack sword2 = new ItemStack (Material.IRON_SWORD);
            ItemStack sword3 = new ItemStack (Material.STONE_SWORD);
            ItemStack sword4 = new ItemStack (Material.DIAMOND_SWORD);
    
            ItemStack axe = new ItemStack (Material.WOOD_AXE);
            ItemStack axe1 = new ItemStack (Material.GOLD_AXE);
            ItemStack axe2 = new ItemStack (Material.IRON_AXE);
            ItemStack axe3 = new ItemStack (Material.STONE_AXE);
            ItemStack axe4 = new ItemStack (Material.DIAMOND_AXE);
           
            ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
            ItemStack chest = new ItemStack (Material.LEATHER_CHESTPLATE);
            ItemStack leggings = new ItemStack (Material.LEATHER_LEGGINGS);
            ItemStack boots = new ItemStack (Material.LEATHER_BOOTS);
    
            ItemStack helmet1 = new ItemStack(Material.CHAINMAIL_HELMET);
            ItemStack chest1 = new ItemStack (Material.CHAINMAIL_CHESTPLATE);
            ItemStack leggings1 = new ItemStack (Material.CHAINMAIL_LEGGINGS);
            ItemStack boots1 = new ItemStack (Material.CHAINMAIL_BOOTS);
           
            ItemStack helmet2 = new ItemStack(Material.IRON_HELMET);
            ItemStack chest2 = new ItemStack (Material.IRON_CHESTPLATE);
            ItemStack leggings2 = new ItemStack (Material.IRON_LEGGINGS);
            ItemStack boots2 = new ItemStack (Material.IRON_BOOTS);
           
            ItemStack helmet3 = new ItemStack(Material.GOLD_HELMET);
            ItemStack chest3 = new ItemStack (Material.GOLD_CHESTPLATE);
            ItemStack leggings3 = new ItemStack (Material.GOLD_LEGGINGS);
            ItemStack boots3 = new ItemStack (Material.GOLD_BOOTS);
           
            ItemStack helmet4 = new ItemStack(Material.DIAMOND_HELMET);
            ItemStack chest4 = new ItemStack (Material.DIAMOND_CHESTPLATE);
            ItemStack leggings4 = new ItemStack (Material.DIAMOND_LEGGINGS);
            ItemStack boots4 = new ItemStack (Material.DIAMOND_BOOTS);
    
    
            setUnbreakable(axe);
            setUnbreakable(sword);
            setUnbreakable(helmet);
            setUnbreakable(chest);
            setUnbreakable(leggings);
            setUnbreakable(boots);
           
            p.getInventory().addItem(axe);
            p.getInventory().addItem(sword);
            p.getInventory().addItem(helmet);
            p.getInventory().addItem(chest);
            p.getInventory().addItem(leggings);
            p.getInventory().addItem(boots);
    
    
            setUnbreakable(axe1);
            setUnbreakable(sword1);
            setUnbreakable(helmet1);
            setUnbreakable(chest1);
            setUnbreakable(leggings1);
            setUnbreakable(boots1);
           
            p.getInventory().addItem(axe1);
            p.getInventory().addItem(sword1);
            p.getInventory().addItem(helmet1);
            p.getInventory().addItem(chest1);
            p.getInventory().addItem(leggings1);
            p.getInventory().addItem(boots1);
    
            setUnbreakable(axe2);
            setUnbreakable(sword2);
            setUnbreakable(helmet2);
            setUnbreakable(chest2);
            setUnbreakable(leggings2);
            setUnbreakable(boots2);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
            setUnbreakable(axe3);
            setUnbreakable(sword3);
            setUnbreakable(helmet3);
            setUnbreakable(chest3);
            setUnbreakable(leggings3);
            setUnbreakable(boots3);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
    
            setUnbreakable(axe4);
            setUnbreakable(sword4);
            setUnbreakable(helmet4);
            setUnbreakable(chest4);
            setUnbreakable(leggings4);
            setUnbreakable(boots4);
           
            p.getInventory().addItem(axe4);
            p.getInventory().addItem(sword4);
            p.getInventory().addItem(helmet4);
            p.getInventory().addItem(chest4);
            p.getInventory().addItem(leggings4);
            p.getInventory().addItem(boots4);
    
    
        }
        private void setUnbreakable(ItemStack item) {
            net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack.setTag(tag);
        }
    }
     
  10. Offline

    timtower Administrator Administrator Moderator

    @HardMCore You didn't register the event in the onEnable.
     
  11. I added onEnable and onDisable, still doesn't work. I was trying to use already made plugins like Unbreakable Equip, Unbreakable etc. but those didnt work too. Can it be server's version fault?
     
  12. Offline

    timtower Administrator Administrator Moderator

    @HardMCore Did you register the event in the onEnable?
     
  13. Yes, I did. There are no errors in Eclipse.

    Code:
    package me.hardmcore.in;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_8_R1.NBTTagCompound;
    
    
    public class Main extends JavaPlugin implements Listener{
       
        @Override
        public void onEnable() {
          Bukkit.getLogger().info("[NoItemBreak] Uruchomiono!");
        }
    
        public void onDisable() {
            Bukkit.getLogger().info("[NoItemBreak] Zatrzymano!");
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            ItemStack sword = new ItemStack (Material.WOOD_SWORD);
            ItemStack sword1 = new ItemStack (Material.GOLD_SWORD);
            ItemStack sword2 = new ItemStack (Material.IRON_SWORD);
            ItemStack sword3 = new ItemStack (Material.STONE_SWORD);
            ItemStack sword4 = new ItemStack (Material.DIAMOND_SWORD);
    
            ItemStack axe = new ItemStack (Material.WOOD_AXE);
            ItemStack axe1 = new ItemStack (Material.GOLD_AXE);
            ItemStack axe2 = new ItemStack (Material.IRON_AXE);
            ItemStack axe3 = new ItemStack (Material.STONE_AXE);
            ItemStack axe4 = new ItemStack (Material.DIAMOND_AXE);
           
            ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
            ItemStack chest = new ItemStack (Material.LEATHER_CHESTPLATE);
            ItemStack leggings = new ItemStack (Material.LEATHER_LEGGINGS);
            ItemStack boots = new ItemStack (Material.LEATHER_BOOTS);
    
            ItemStack helmet1 = new ItemStack(Material.CHAINMAIL_HELMET);
            ItemStack chest1 = new ItemStack (Material.CHAINMAIL_CHESTPLATE);
            ItemStack leggings1 = new ItemStack (Material.CHAINMAIL_LEGGINGS);
            ItemStack boots1 = new ItemStack (Material.CHAINMAIL_BOOTS);
           
            ItemStack helmet2 = new ItemStack(Material.IRON_HELMET);
            ItemStack chest2 = new ItemStack (Material.IRON_CHESTPLATE);
            ItemStack leggings2 = new ItemStack (Material.IRON_LEGGINGS);
            ItemStack boots2 = new ItemStack (Material.IRON_BOOTS);
           
            ItemStack helmet3 = new ItemStack(Material.GOLD_HELMET);
            ItemStack chest3 = new ItemStack (Material.GOLD_CHESTPLATE);
            ItemStack leggings3 = new ItemStack (Material.GOLD_LEGGINGS);
            ItemStack boots3 = new ItemStack (Material.GOLD_BOOTS);
           
            ItemStack helmet4 = new ItemStack(Material.DIAMOND_HELMET);
            ItemStack chest4 = new ItemStack (Material.DIAMOND_CHESTPLATE);
            ItemStack leggings4 = new ItemStack (Material.DIAMOND_LEGGINGS);
            ItemStack boots4 = new ItemStack (Material.DIAMOND_BOOTS);
    
    
            setUnbreakable(axe);
            setUnbreakable(sword);
            setUnbreakable(helmet);
            setUnbreakable(chest);
            setUnbreakable(leggings);
            setUnbreakable(boots);
           
            p.getInventory().addItem(axe);
            p.getInventory().addItem(sword);
            p.getInventory().addItem(helmet);
            p.getInventory().addItem(chest);
            p.getInventory().addItem(leggings);
            p.getInventory().addItem(boots);
    
    
            setUnbreakable(axe1);
            setUnbreakable(sword1);
            setUnbreakable(helmet1);
            setUnbreakable(chest1);
            setUnbreakable(leggings1);
            setUnbreakable(boots1);
           
            p.getInventory().addItem(axe1);
            p.getInventory().addItem(sword1);
            p.getInventory().addItem(helmet1);
            p.getInventory().addItem(chest1);
            p.getInventory().addItem(leggings1);
            p.getInventory().addItem(boots1);
    
            setUnbreakable(axe2);
            setUnbreakable(sword2);
            setUnbreakable(helmet2);
            setUnbreakable(chest2);
            setUnbreakable(leggings2);
            setUnbreakable(boots2);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
            setUnbreakable(axe3);
            setUnbreakable(sword3);
            setUnbreakable(helmet3);
            setUnbreakable(chest3);
            setUnbreakable(leggings3);
            setUnbreakable(boots3);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
    
            setUnbreakable(axe4);
            setUnbreakable(sword4);
            setUnbreakable(helmet4);
            setUnbreakable(chest4);
            setUnbreakable(leggings4);
            setUnbreakable(boots4);
           
            p.getInventory().addItem(axe4);
            p.getInventory().addItem(sword4);
            p.getInventory().addItem(helmet4);
            p.getInventory().addItem(chest4);
            p.getInventory().addItem(leggings4);
            p.getInventory().addItem(boots4);
    
    
        }
        private void setUnbreakable(ItemStack item) {
            net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack.setTag(tag);
        }
    }
     
  14. Offline

    timtower Administrator Administrator Moderator

  15. Okay, I registered, it gives me items, but those are not unbreakable. Dont even have the "Unbreakable" lore. And I also wanted to make that every item, even this crafted and given by other player will be unbreakable.

    Code:
    Code:
    package me.hardmcore.in;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_8_R1.NBTTagCompound;
    
    
    public class Main extends JavaPlugin implements Listener{
    
        public void onEnable() {
            
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            
            }
    
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            ItemStack sword = new ItemStack (Material.WOOD_SWORD);
            ItemStack sword1 = new ItemStack (Material.GOLD_SWORD);
            ItemStack sword2 = new ItemStack (Material.IRON_SWORD);
            ItemStack sword3 = new ItemStack (Material.STONE_SWORD);
            ItemStack sword4 = new ItemStack (Material.DIAMOND_SWORD);
    
            ItemStack axe = new ItemStack (Material.WOOD_AXE);
            ItemStack axe1 = new ItemStack (Material.GOLD_AXE);
            ItemStack axe2 = new ItemStack (Material.IRON_AXE);
            ItemStack axe3 = new ItemStack (Material.STONE_AXE);
            ItemStack axe4 = new ItemStack (Material.DIAMOND_AXE);
           
            ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
            ItemStack chest = new ItemStack (Material.LEATHER_CHESTPLATE);
            ItemStack leggings = new ItemStack (Material.LEATHER_LEGGINGS);
            ItemStack boots = new ItemStack (Material.LEATHER_BOOTS);
    
            ItemStack helmet1 = new ItemStack(Material.CHAINMAIL_HELMET);
            ItemStack chest1 = new ItemStack (Material.CHAINMAIL_CHESTPLATE);
            ItemStack leggings1 = new ItemStack (Material.CHAINMAIL_LEGGINGS);
            ItemStack boots1 = new ItemStack (Material.CHAINMAIL_BOOTS);
           
            ItemStack helmet2 = new ItemStack(Material.IRON_HELMET);
            ItemStack chest2 = new ItemStack (Material.IRON_CHESTPLATE);
            ItemStack leggings2 = new ItemStack (Material.IRON_LEGGINGS);
            ItemStack boots2 = new ItemStack (Material.IRON_BOOTS);
           
            ItemStack helmet3 = new ItemStack(Material.GOLD_HELMET);
            ItemStack chest3 = new ItemStack (Material.GOLD_CHESTPLATE);
            ItemStack leggings3 = new ItemStack (Material.GOLD_LEGGINGS);
            ItemStack boots3 = new ItemStack (Material.GOLD_BOOTS);
           
            ItemStack helmet4 = new ItemStack(Material.DIAMOND_HELMET);
            ItemStack chest4 = new ItemStack (Material.DIAMOND_CHESTPLATE);
            ItemStack leggings4 = new ItemStack (Material.DIAMOND_LEGGINGS);
            ItemStack boots4 = new ItemStack (Material.DIAMOND_BOOTS);
    
    
            setUnbreakable(axe);
            setUnbreakable(sword);
            setUnbreakable(helmet);
            setUnbreakable(chest);
            setUnbreakable(leggings);
            setUnbreakable(boots);
           
            p.getInventory().addItem(axe);
            p.getInventory().addItem(sword);
            p.getInventory().addItem(helmet);
            p.getInventory().addItem(chest);
            p.getInventory().addItem(leggings);
            p.getInventory().addItem(boots);
    
    
            setUnbreakable(axe1);
            setUnbreakable(sword1);
            setUnbreakable(helmet1);
            setUnbreakable(chest1);
            setUnbreakable(leggings1);
            setUnbreakable(boots1);
           
            p.getInventory().addItem(axe1);
            p.getInventory().addItem(sword1);
            p.getInventory().addItem(helmet1);
            p.getInventory().addItem(chest1);
            p.getInventory().addItem(leggings1);
            p.getInventory().addItem(boots1);
    
            setUnbreakable(axe2);
            setUnbreakable(sword2);
            setUnbreakable(helmet2);
            setUnbreakable(chest2);
            setUnbreakable(leggings2);
            setUnbreakable(boots2);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
            setUnbreakable(axe3);
            setUnbreakable(sword3);
            setUnbreakable(helmet3);
            setUnbreakable(chest3);
            setUnbreakable(leggings3);
            setUnbreakable(boots3);
           
            p.getInventory().addItem(axe3);
            p.getInventory().addItem(sword3);
            p.getInventory().addItem(helmet3);
            p.getInventory().addItem(chest3);
            p.getInventory().addItem(leggings3);
            p.getInventory().addItem(boots3);
    
            setUnbreakable(axe4);
            setUnbreakable(sword4);
            setUnbreakable(helmet4);
            setUnbreakable(chest4);
            setUnbreakable(leggings4);
            setUnbreakable(boots4);
           
            p.getInventory().addItem(axe4);
            p.getInventory().addItem(sword4);
            p.getInventory().addItem(helmet4);
            p.getInventory().addItem(chest4);
            p.getInventory().addItem(leggings4);
            p.getInventory().addItem(boots4);
    
    
        }
        private void setUnbreakable(ItemStack item) {
            net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack.setTag(tag);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page