/src/pocketmine/command/defaults/FillCommand.php

https://gitlab.com/wesleyvanneck/ImagicalMine · PHP · 89 lines · 58 code · 8 blank · 23 comment · 8 complexity · a738c016c631aa80d4ebe68b0a2a923e MD5 · raw file

  1. <?php
  2. /*
  3. *
  4. * _ _ _ __ __ _
  5. * (_) (_) | | \/ (_)
  6. * _ _ __ ___ __ _ __ _ _ ___ __ _| | \ / |_ _ __ ___
  7. * | | '_ ` _ \ / _` |/ _` | |/ __/ _` | | |\/| | | '_ \ / _ \
  8. * | | | | | | | (_| | (_| | | (_| (_| | | | | | | | | | __/
  9. * |_|_| |_| |_|\__,_|\__, |_|\___\__,_|_|_| |_|_|_| |_|\___|
  10. * __/ |
  11. * |___/
  12. *
  13. * This program is a third party build by ImagicalMine.
  14. *
  15. * PocketMine is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Lesser General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * @author ImagicalMine Team
  21. * @link http://forums.imagicalcorp.ml/
  22. *
  23. *
  24. */
  25. namespace pocketmine\command\defaults;
  26. use pocketmine\command\CommandSender;
  27. use pocketmine\event\TranslationContainer;
  28. use pocketmine\Player;
  29. use pocketmine\utils\TextFormat;
  30. use pocketmine\math\Vector3;
  31. use pocketmine\item\ItemBlock;
  32. use pocketmine\item\Item;
  33. use pocketmine\level\Level;
  34. class FillCommand extends VanillaCommand
  35. {
  36. public function __construct($name)
  37. {
  38. parent::__construct(
  39. $name,
  40. "%pocketmine.command.fill.description",
  41. "%commands.fill.usage"
  42. );
  43. $this->setPermission("pocketmine.command.fill");
  44. }
  45. public function execute(CommandSender $sender, $label, array $args)
  46. {
  47. if (!$this->testPermission($sender)) {
  48. return true;
  49. }
  50. for ($a = 0; $a < 6; $a++) {
  51. if (isset($args[$a])) {
  52. if (is_integer($args[$a])) {
  53. if (Item::fromString($args[6]) instanceof ItemBlock) {
  54. for ($x = $args[0]; $x <= $args[3]; $x++) {
  55. for ($y = $args[1]; $y <= $args[4]; $y++) {
  56. for ($z = $args[2]; $z <= $args[5]; $z++) {
  57. $this->setBlock(new Vector3($x, $y, $z), $sender->getLevel(), Item::fromString($args[6]), isset($args[7]) ? $args[7] : 0);
  58. $sender->sendMessage();
  59. return true;
  60. }
  61. }
  62. }
  63. }
  64. $sender->sendMessage(TextFormat::RED . new TranslationContainer("pocketmine.command.fill.invalidBlock", []));
  65. return false;
  66. }
  67. $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
  68. return false;
  69. }
  70. $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
  71. return false;
  72. }
  73. }
  74. private function setBlock(Vector3 $p, Level $lvl, ItemBlock $b, $meta)
  75. {
  76. $block = $b->getBlock();
  77. $block->setDamage($meta);
  78. $lvl->setBlock($p, $b);
  79. return true;
  80. }
  81. }