changing durability issues?

Discussion in 'Plugin Development' started by BeastyBoo, Sep 4, 2016.

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

    BeastyBoo

    I dont see how that would help?
     
  2. Offline

    ArsenArsen

    Runs task after the event actually fires, tyvm
     
  3. Offline

    BeastyBoo

    It didnt work :/
     
  4. Offline

    ArsenArsen

    @BeastyBoo what does it do at this point? Also post updated code.
     
  5. Offline

    BeastyBoo

    @ArsenArsen
    It still doesnt work. It doesnt countdown. this is my updated code:
    Code:
    public ItemStack DamageFishingRod(ItemStack is){
            is = new ItemStack(Material.FISHING_ROD, 1);
            ItemMeta im = is.getItemMeta();
            im.setDisplayName(ChatColor.GOLD + "Grapple Hook");
            List<String> lore = new ArrayList<String>();
    
            //This gets the uses left and adds it to the lore
            int currentUses = (int)((((double)64)-((double)is.getDurability()))/64*50);
            lore.add(0, "Uses Left: "+ currentUses);
            System.out.println("currentUses: " + currentUses);
            im.setLore(lore);
            is.setItemMeta(im);
    
            //Returns the item stack.
            return is;
            }
    
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
            sender.sendMessage("§cOnly players can use this command");
            return true;
            }
            if(label.equalsIgnoreCase("Grapple")) {
            Player p = (Player) sender;
            if (p.hasPermission("Grapple.Grapple")) {
            p.getInventory().addItem(DamageFishingRod(new ItemStack(Material.FISHING_ROD)));
            } else {
            p.sendMessage("§cYou dont have permission to use this command.");
            }
            }
            return false;
            }
    
            @EventHandler
            public void Check(PlayerInteractEvent e) {
            final Player p = e.getPlayer();
    
    
    
            if(p.getItemInHand().equals(Material.FISHING_ROD) && p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Grapple Hook")) {
    
                if (cooldownTick.contains(p)) {
                    return;
            }
    
            final ItemStack copy = DamageFishingRod( p.getItemInHand());
    
            //This gets the DISPLAYED durability and converts it into the actual durability.
            int durability = Integer.parseInt(p.getItemInHand().getItemMeta().getLore().get(0).split(":")[1]);
            copy.setDurability((short) ((short)64-(((double)durability)/50*64)));
    
            //This resets the item in the player's hand.
            p.getInventory().setItemInHand(copy);
          
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    p.updateInventory();
                    System.out.println("currentUsesInter: " + copy.getDurability());
                }
           }, 5);
          
            cooldownTick.add(p);
          
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    cooldownTick.remove(p);
                }
        }, 5);
          
          
          
    
            } else {
            return;
            }
            }

    I added cooldown to the grapple hook itself to, it made it look alot better. thanks for the tips :D
     
  6. Offline

    ArsenArsen

    I have no idea right now.. And i have to leave.. Sorry @BeastyBoo
     
  7. Offline

    BeastyBoo

    @ArsenArsen
    thanks for the help I have recived from you.
     
    ArsenArsen likes this.
Thread Status:
Not open for further replies.

Share This Page