mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
GiveCommand: don't crash when an invalid item is specified
This commit is contained in:
parent
4c583ec8ab
commit
aeba15c5c6
@ -54,7 +54,12 @@ class GiveCommand extends VanillaCommand{
|
||||
}
|
||||
|
||||
$player = $sender->getServer()->getPlayer($args[0]);
|
||||
$item = ItemFactory::fromString($args[1]);
|
||||
try{
|
||||
$item = ItemFactory::fromString($args[1]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]]));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!isset($args[2])){
|
||||
$item->setCount($item->getMaxStackSize());
|
||||
@ -80,12 +85,6 @@ class GiveCommand extends VanillaCommand{
|
||||
}
|
||||
|
||||
if($player instanceof Player){
|
||||
if($item->getId() === 0){
|
||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: overflow
|
||||
$player->getInventory()->addItem(clone $item);
|
||||
}else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user