Coder Social home page Coder Social logo

Comments (4)

legoboy0215 avatar legoboy0215 commented on May 27, 2024 2

Because of this, I had to resort to other methods like iterating through the player's inventory.

from pocketmine-mp.

SOF3 avatar SOF3 commented on May 27, 2024 2

Why would you run break; after a return true; statement 😕 it is dead code.

from pocketmine-mp.

Intyre avatar Intyre commented on May 27, 2024 2

It works fine for me.

Run ci first to clean the inventory and then ic twice. First time it will add the items and second time it doesn't because the inventory contains the items.

https://github.com/pmmp/PocketMine-MP/blob/0.16/src/pocketmine/item/Item.php#L548
https://github.com/pmmp/PocketMine-MP/blob/0.16/src/pocketmine/inventory/BaseInventory.php#L162
$checkTags = $item->getCompoundTag() === null ? false : true;

public function onCommand(CommandSender $sender, Command $command, $label, array $args){
    if(!($sender instanceof Player)){
       $this->getLogger()->info("Not a Player!");
       return true;
    }
    switch($command->getName()){
        case "ic":
           $item = Item::get(Item::STONE, 0, 1);
           if(!$sender->getInventory()->contains($item)){
               $this->getLogger()->info("Item not found");
               $sender->getInventory()->addItem(clone $item);
           }

           $item->setCustomName("Not stone");
           if(!$sender->getInventory()->contains($item)){
               $this->getLogger()->info("Item with custom name not found");
               $sender->getInventory()->addItem(clone $item);
           }
           return true;
        case "ci":
           $sender->getInventory()->clearAll();
           return true;
        default:
           return false;
    }
}

from pocketmine-mp.

Sandertv avatar Sandertv commented on May 27, 2024

Hmmm I must have done something wrong then...

from pocketmine-mp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.