56 $target = $this->fetchPermittedPlayerTarget($sender, $args[0] ??
null, DefaultPermissionNames::COMMAND_CLEAR_SELF, DefaultPermissionNames::COMMAND_CLEAR_OTHER);
65 $targetItem = StringToItemParser::getInstance()->parse($args[1]) ?? LegacyStringToItemParser::getInstance()->parse($args[1]);
68 $targetItem->setCount($maxCount = $this->getInteger($sender, $args[2], -1));
72 $sender->sendMessage(KnownTranslationFactory::commands_give_item_notFound($args[1])->prefix(TextFormat::RED));
81 $target->getInventory(),
82 $target->getCursorInventory(),
83 $target->getArmorInventory(),
84 $target->getOffHandInventory()
88 if($targetItem !==
null && $maxCount === 0){
89 $count = $this->
countItems($inventories, $targetItem);
91 $sender->sendMessage(KnownTranslationFactory::commands_clear_testing($target->getName(), (
string) $count));
93 $sender->sendMessage(KnownTranslationFactory::commands_clear_failure_no_items($target->getName())->prefix(TextFormat::RED));
100 if($targetItem ===
null){
102 $clearedCount += $this->
countItems($inventories,
null);
103 foreach($inventories as $inventory){
104 $inventory->clearAll();
108 if($maxCount === -1){
109 $clearedCount += $this->
countItems($inventories, $targetItem);
110 foreach($inventories as $inventory){
111 $inventory->remove($targetItem);
115 foreach($inventories as $inventory){
116 foreach($inventory->all($targetItem) as $index => $item){
118 $reductionCount = min($item->getCount(), $maxCount);
119 $item->pop($reductionCount);
120 $clearedCount += $reductionCount;
121 $inventory->setItem($index, $item);
123 $maxCount -= $reductionCount;
132 if($clearedCount > 0){
133 Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_clear_success($target->getName(), (
string) $clearedCount));
135 $sender->sendMessage(KnownTranslationFactory::commands_clear_failure_no_items($target->getName())->prefix(TextFormat::RED));