mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-19 01:44:06 +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]);
|
$player = $sender->getServer()->getPlayer($args[0]);
|
||||||
|
try{
|
||||||
$item = ItemFactory::fromString($args[1]);
|
$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])){
|
if(!isset($args[2])){
|
||||||
$item->setCount($item->getMaxStackSize());
|
$item->setCount($item->getMaxStackSize());
|
||||||
@ -80,12 +85,6 @@ class GiveCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
if($item->getId() === 0){
|
|
||||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]]));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: overflow
|
//TODO: overflow
|
||||||
$player->getInventory()->addItem(clone $item);
|
$player->getInventory()->addItem(clone $item);
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user