1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

how can i fix an item?

Discussion in 'Development' started by Levi, Oct 29, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    how can I set an item's durability\damage to like a brand new one?
    my try :
    PHP:
    public function execute(CommandSender $senderstring $commandLable, array $args): bool
        
    {
            if (!
    $sender instanceof Player) {
                
    $sender->sendMessage($this->plugin->p);
                return 
    true;
            }
            if (
    $sender->hasPermission("fix")) {
                
    $item $sender->getInventory()->getItemInHand();
                
    $item->setDamage(1000);
            }else{
                
    $sender->sendMessage($this->plugin->noperm);
            }
            return 
    true;
        }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    public function execute(CommandSender $senderstring $commandLabel, array $args): bool
    {
       if (!
    $sender instanceof Player) {
          
    $sender->sendMessage($this->plugin->p);
          return 
    true;
       }
       if (
    $sender->hasPermission("fix")) {
          
    $item $sender->getInventory()->getItemInHand();
          if(
    $item instanceof Tool)
             
    $item->setDamage($item->getMaxDurability()); // if not then it's 0
       
    }else{
          
    $sender->sendMessage($this->plugin->noperm);
       }
       return 
    true;
    }
     
    Last edited: Nov 2, 2017
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Well you're breaking the item there :p
     
    jasonwynn10 and Jack Noordhuis like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.