mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
GiveCommand: Make invalid player checking logic less confusing
some code in this namespace is just total WTF...
This commit is contained in:
parent
aeba15c5c6
commit
c26e3aa9fa
@ -54,6 +54,11 @@ class GiveCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$player = $sender->getServer()->getPlayer($args[0]);
|
$player = $sender->getServer()->getPlayer($args[0]);
|
||||||
|
if($player === null){
|
||||||
|
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$item = ItemFactory::fromString($args[1]);
|
$item = ItemFactory::fromString($args[1]);
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(\InvalidArgumentException $e){
|
||||||
@ -84,14 +89,8 @@ class GiveCommand extends VanillaCommand{
|
|||||||
$item->setNamedTag($tags);
|
$item->setNamedTag($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($player instanceof Player){
|
|
||||||
//TODO: overflow
|
//TODO: overflow
|
||||||
$player->getInventory()->addItem(clone $item);
|
$player->getInventory()->addItem(clone $item);
|
||||||
}else{
|
|
||||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [
|
Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [
|
||||||
$item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")",
|
$item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user