diff --git a/plugin.yml b/plugin.yml index bc87c12f..fb8595c0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ --- name: "BlockSniper" -version: 1.0.1 +version: 1.2.0 api: [2.0.0, 2.1.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3] author: "Sandertv" main: Sandertv\BlockSniper\Loader @@ -69,6 +69,9 @@ permissions: blocksniper.type.biome: default: op description: "Allows access to the biome type" + blocksniper.type.raise: + default: op + description: "Allows access to the raise type" blocksniper.shape: default: false description: "Allows access to all BlockSniper shapes." diff --git a/resources/settings.yml b/resources/settings.yml index f6f17ee2..09643a69 100644 --- a/resources/settings.yml +++ b/resources/settings.yml @@ -12,7 +12,7 @@ Brush-Item: 396 Maximum-Radius: 15 # Maximum undo stores to save, old ones will get destroyed automatically. Setting this number too high could result in lag or data loss. -Maximum-Undo-Stores: 7 +Maximum-Undo-Stores: 15 # Whether to reset the size, or make it remain the current size when smallest size with decrement brush is reached. Reset-Decrement-Brush: true diff --git a/src/Sandertv/BlockSniper/Loader.php b/src/Sandertv/BlockSniper/Loader.php index 23188151..0d42c013 100644 --- a/src/Sandertv/BlockSniper/Loader.php +++ b/src/Sandertv/BlockSniper/Loader.php @@ -17,7 +17,7 @@ class Loader extends PluginBase { - const VERSION = "1.1.0"; + const VERSION = "1.2.0"; const API_TARGET = "2.0.0 - 3.0.0-ALPHA3"; public $undoStore; @@ -37,7 +37,13 @@ class Loader extends PluginBase { public $language; public function onEnable() { - $this->getLogger()->info(TF::GREEN . "BlockSniper has been enabled."); + $this->reloadAll(); + + $this->registerCommands(); + $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); + } + + public function reloadAll() { $this->brush = new Brush($this); $this->undoStore = new UndoStorer($this); $this->cloneStore = new CloneStorer($this); @@ -47,21 +53,18 @@ public function onEnable() { if(!is_dir($this->getDataFolder() . "templates/")) { mkdir($this->getDataFolder() . "templates/"); } - $this->saveResource("settings.yml"); - $this->settings = new Config($this->getDataFolder() . "settings.yml", Config::YAML); - - // Language file setup if(!is_dir($this->getDataFolder() . "languages/")) { mkdir($this->getDataFolder() . "languages/"); } + + $this->saveResource("settings.yml"); + $this->settings = new Config($this->getDataFolder() . "settings.yml", Config::YAML); + if(!$this->setupLanguageFile()) { $this->getLogger()->info(TF::AQUA . "[BlockSniper] No valid language selected, English has been auto-selected.\n" . TF::AQUA . "Please setup a language by using /blocksniper language ."); } else { $this->getLogger()->info(TF::AQUA . "[BlockSniper] Language selected: " . TF::GREEN . $this->getSettings()->get("Message-Language")); } - - $this->registerCommands(); - $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); } /** diff --git a/src/Sandertv/BlockSniper/UndoStorer.php b/src/Sandertv/BlockSniper/UndoStorer.php index 34bcdcce..b13fc9ce 100644 --- a/src/Sandertv/BlockSniper/UndoStorer.php +++ b/src/Sandertv/BlockSniper/UndoStorer.php @@ -8,7 +8,7 @@ class UndoStorer { - public $totalStores = 0; + public $totalStores; public $undoStore = []; public $lastUndo; @@ -33,8 +33,8 @@ public function saveUndo(array $blocks) { } unset($i); - if(count($this->undoStore) === $this->getOwner()->settings->get("Maximum-Undo-Stores")) { - $this->unsetFirstUndo(); // Unset the first undo to make sure the array won't get too big. + if($this->getTotalUndoStores() === $this->getOwner()->settings->get("Maximum-Undo-Stores")) { + $this->unsetFirstUndo(); } $this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask(new UndoDiminishTask($this->getOwner()), 2400); @@ -52,20 +52,22 @@ public function unsetFirstUndo() { unset($this->undoStore[min(array_keys($this->undoStore))]); } - public function restoreLastUndo() { - foreach($this->undoStore[max(array_keys($this->undoStore))] as $key => $block) { - $Id = explode("(", $key); - $blockId = $Id[0]; - $meta = explode(":", $blockId); - $meta = $meta[1]; - $x = $block["x"]; - $y = $block["y"]; - $z = $block["z"]; - $finalBlock = Item::get($blockId, $meta)->getBlock(); - $finalBlock->setDamage((int)$meta !== null ? $meta : 0); - $this->getOwner()->getServer()->getLevelByName($block["level"])->setBlock(new Vector3($x, $y, $z), $finalBlock, false, false); + public function restoreLastUndo(int $amount = 1) { + for($currentAmount = 0; $currentAmount < $amount; $currentAmount++) { + foreach($this->undoStore[max(array_keys($this->undoStore))] as $key => $block) { + $Id = explode("(", $key); + $blockId = $Id[0]; + $meta = explode(":", $blockId); + $meta = $meta[1]; + $x = $block["x"]; + $y = $block["y"]; + $z = $block["z"]; + $finalBlock = Item::get($blockId, $meta)->getBlock(); + $finalBlock->setDamage((int)$meta !== null ? $meta : 0); + $this->getOwner()->getServer()->getLevelByName($block["level"])->setBlock(new Vector3($x, $y, $z), $finalBlock, false, false); + } + $this->unsetLastUndo(); } - $this->unsetLastUndo(); } public function unsetLastUndo() { @@ -81,7 +83,7 @@ public function resetUndoStorage() { * @return bool */ public function undoStorageExists() { - if($this->totalStores === 0 || !is_array($this->undoStore) || empty($this->undoStore)) { + if(!is_array($this->undoStore) || empty($this->undoStore)) { return false; } return true; @@ -100,4 +102,11 @@ public function getLastUndoBlockAmount() { public function getLastUndoActivity(): int { return (time() - $this->lastUndo); } + + /** + * @return int + */ + public function getTotalUndoStores(): int { + return count($this->undoStore); + } } diff --git a/src/Sandertv/BlockSniper/brush/BaseShape.php b/src/Sandertv/BlockSniper/brush/BaseShape.php index f3f8abec..cc30f964 100644 --- a/src/Sandertv/BlockSniper/brush/BaseShape.php +++ b/src/Sandertv/BlockSniper/brush/BaseShape.php @@ -9,8 +9,8 @@ abstract class BaseShape { const MAX_WORLD_HEIGHT = 256; const MIN_WORLD_HEIGHT = 0; - const SHAPE_CUBE = 0; - const SHAPE_SPHERE = 1; + const SHAPE_SPHERE = 0; + const SHAPE_CUBE = 1; const SHAPE_CYLINDER = 2; const SHAPE_CUBOID = 3; @@ -18,6 +18,40 @@ public function __construct(Loader $main) { $this->main = $main; } + /** + * @param string $shape + * + * @return bool + */ + public static function isShape(string $shape): bool { + $shapeConst = strtoupper("shape_" . $shape); + if(defined("self::$shapeConst")) { + return true; + } + return false; + } + + /** + * Registers a new Shape. Example: + * Triangle, 4 + * + * Defines the shape as a constant making it able to be used. + * + * + * @param string $shape + * @param int $number + * + * @return bool + */ + public static function registerShape(string $shape, int $number): bool { + $shapeConst = strtoupper("shape_" . str_replace("_", "", $shape)); + if(defined("self::$shapeConst")) { + return false; + } + define(('Sandertv\BlockSniper\brush\BaseShape\\' . $shapeConst), $number); + return true; + } + public abstract function getName(): string; public abstract function getPermission(): string; diff --git a/src/Sandertv/BlockSniper/brush/BaseType.php b/src/Sandertv/BlockSniper/brush/BaseType.php index 35c76fe7..3dd2b1c0 100644 --- a/src/Sandertv/BlockSniper/brush/BaseType.php +++ b/src/Sandertv/BlockSniper/brush/BaseType.php @@ -15,12 +15,13 @@ abstract class BaseType { const TYPE_REPLACE = 3; const TYPE_FLATTEN = 4; const TYPE_DRAIN = 5; - const TYPE_LEAF_BLOWER = 6; + const TYPE_LEAFBLOWER = 6; const TYPE_CLEAN = 7; const TYPE_BIOME = 8; - const TYPE_CLEAN_ENTITIES = 9; + const TYPE_CLEANENTITIES = 9; const TYPE_MELT = 10; const TYPE_EXPAND = 11; + const TYPE_RAISE = 12; public $main; @@ -28,6 +29,40 @@ public function __construct(Loader $main) { $this->main = $main; } + /** + * @param string $type + * + * @return bool + */ + public static function isType(string $type): bool { + $typeConst = strtoupper("type_" . $type); + if(defined("self::$typeConst")) { + return true; + } + return false; + } + + /** + * Registers a new Type. Example: + * Raise, 12 + * + * Defines the type as a constant making it able to be used. + * + * + * @param string $type + * @param int $number + * + * @return bool + */ + public static function registerType(string $type, int $number): bool { + $typeConst = strtoupper("type_" . str_replace("_", "", $type)); + if(defined("self::$typeConst")) { + return false; + } + define(('Sandertv\BlockSniper\brush\BaseType\\' . $typeConst), $number); + return true; + } + public abstract function getName(): string; public abstract function getPermission(): string; diff --git a/src/Sandertv/BlockSniper/brush/Brush.php b/src/Sandertv/BlockSniper/brush/Brush.php index 97133ed3..0bbb32a4 100644 --- a/src/Sandertv/BlockSniper/brush/Brush.php +++ b/src/Sandertv/BlockSniper/brush/Brush.php @@ -6,22 +6,6 @@ use pocketmine\item\Item; use pocketmine\Player; use ReflectionClass; -use Sandertv\BlockSniper\brush\shapes\CubeShape; -use Sandertv\BlockSniper\brush\shapes\CuboidShape; -use Sandertv\BlockSniper\brush\shapes\CylinderStandingShape; -use Sandertv\BlockSniper\brush\shapes\SphereShape; -use Sandertv\BlockSniper\brush\types\BiomeType; -use Sandertv\BlockSniper\brush\types\CleanEntitiesType; -use Sandertv\BlockSniper\brush\types\CleanType; -use Sandertv\BlockSniper\brush\types\DrainType; -use Sandertv\BlockSniper\brush\types\ExpandType; -use Sandertv\BlockSniper\brush\types\FillType; -use Sandertv\BlockSniper\brush\types\FlattenType; -use Sandertv\BlockSniper\brush\types\LayerType; -use Sandertv\BlockSniper\brush\types\LeafBlowerType; -use Sandertv\BlockSniper\brush\types\MeltType; -use Sandertv\BlockSniper\brush\types\OverlayType; -use Sandertv\BlockSniper\brush\types\ReplaceType; use Sandertv\BlockSniper\Loader; class Brush { @@ -188,25 +172,9 @@ public static function setShape(Player $player, string $shape) { * @return BaseShape */ public static function getShape(Player $player): BaseShape { - $shapeName = self::$brush[$player->getId()]["shape"]; - switch($shapeName) { - case "cube": - $shape = new CubeShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100)); - break; - case "sphere": - $shape = new SphereShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100)); - break; - case "cuboid": - $shape = new CuboidShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100)); - break; - case "cylinder": - $shape = new CylinderStandingShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100)); - break; - - default: - $shape = new SphereShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100)); - break; - } + $shapeName = 'Sandertv\BlockSniper\brush\shapes\\' . (ucfirst(self::$brush[$player->getId()]["shape"]) . "Shape"); + $shape = new $shapeName(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100)); + return $shape; } @@ -235,49 +203,9 @@ public static function getHeight(Player $player): int { * @return BaseType */ public static function getType(Player $player, array $blocks = []): BaseType { - $typeName = self::$brush[$player->getId()]["type"]; - switch($typeName) { - case "fill": - $type = new FillType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "clean": - $type = new CleanType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "drain": - $type = new DrainType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "flatten": - $type = new FlattenType(self::$owner, $player, $player->getLevel(), $blocks, $player->getTargetBlock(100)); - break; - case "layer": - $type = new LayerType(self::$owner, $player, $player->getLevel(), $blocks, $player->getTargetBlock(100)); - break; - case "leafblower": - $type = new LeafBlowerType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "overlay": - $type = new OverlayType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "replace": - $type = new ReplaceType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "expand": - $type = new ExpandType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "melt": - $type = new MeltType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "cleanentities": - $type = new CleanEntitiesType(self::$owner, $player, $player->getLevel(), $blocks); - break; - case "biome": - $type = new BiomeType(self::$owner, $player, $player->getLevel(), $blocks); - break; - - default: - $type = new FillType(self::$owner, $player, $player->getLevel(), $blocks); - break; - } + $typeName = 'Sandertv\BlockSniper\brush\types\\' . (ucfirst(self::$brush[$player->getId()]["type"]) . "Type"); + $type = new $typeName(self::$owner, $player, $player->getLevel(), $blocks); + return $type; } @@ -289,7 +217,7 @@ public static function setBiome(Player $player, string $biome) { self::$brush[$player->getId()]["biome"] = $biome; } - public static function getBiomeIdFromString(Player $player): int { + public static function getBiomeId(Player $player): int { $biomes = new ReflectionClass('pocketmine\level\generator\biome\Biome'); $const = strtoupper(str_replace(" ", "_", self::$brush[$player->getId()]["biome"])); if($biomes->hasConstant($const)) { diff --git a/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php b/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php index 85cc0e9b..8682d133 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php @@ -18,11 +18,11 @@ class CuboidShape extends BaseShape { public $center; public $player; - public function __construct(Loader $main, Player $player, Level $level, float $width = null, float $height = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, float $width = null, Position $center = null) { parent::__construct($main); $this->level = $level; $this->width = $width; - $this->height = $height; + $this->height = Brush::getHeight($player); $this->center = $center; $this->player = $player; } diff --git a/src/Sandertv/BlockSniper/brush/shapes/CylinderStandingShape.php b/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php similarity index 93% rename from src/Sandertv/BlockSniper/brush/shapes/CylinderStandingShape.php rename to src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php index 7badd79d..098a042a 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/CylinderStandingShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php @@ -10,7 +10,7 @@ use Sandertv\BlockSniper\brush\Brush; use Sandertv\BlockSniper\Loader; -class CylinderStandingShape extends BaseShape { +class CylinderShape extends BaseShape { public $level; public $radius; @@ -18,11 +18,11 @@ class CylinderStandingShape extends BaseShape { public $player; public $center; - public function __construct(Loader $main, Player $player, Level $level, float $radius = null, int $height = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, float $radius = null, Position $center = null) { parent::__construct($main); $this->level = $level; $this->radius = $radius; - $this->height = $height; + $this->height = Brush::getHeight($player); $this->center = $center; $this->player = $player; } diff --git a/src/Sandertv/BlockSniper/brush/types/BiomeType.php b/src/Sandertv/BlockSniper/brush/types/BiomeType.php index 2f6ef9ab..5f55b60a 100644 --- a/src/Sandertv/BlockSniper/brush/types/BiomeType.php +++ b/src/Sandertv/BlockSniper/brush/types/BiomeType.php @@ -27,7 +27,7 @@ public function __construct(Loader $main, Player $player, Level $level, array $b */ public function fillShape(): bool { foreach($this->blocks as $block) { - $this->level->setBiomeId($block->x, $block->z, Brush::getBiomeIdFromString($this->player)); + $this->level->setBiomeId($block->x, $block->z, Brush::getBiomeId($this->player)); } return true; } diff --git a/src/Sandertv/BlockSniper/brush/types/CleanEntitiesType.php b/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php similarity index 95% rename from src/Sandertv/BlockSniper/brush/types/CleanEntitiesType.php rename to src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php index 6cfb76af..78112c61 100644 --- a/src/Sandertv/BlockSniper/brush/types/CleanEntitiesType.php +++ b/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php @@ -7,7 +7,7 @@ use Sandertv\BlockSniper\brush\BaseType; use Sandertv\BlockSniper\Loader; -class CleanEntitiesType extends BaseType { +class CleanentitiesType extends BaseType { public $level; public $blocks; diff --git a/src/Sandertv/BlockSniper/brush/types/ExpandType.php b/src/Sandertv/BlockSniper/brush/types/ExpandType.php index 118549be..0a16739c 100644 --- a/src/Sandertv/BlockSniper/brush/types/ExpandType.php +++ b/src/Sandertv/BlockSniper/brush/types/ExpandType.php @@ -28,19 +28,22 @@ public function __construct(Loader $main, Player $player, Level $level, array $b public function fillShape(): bool { $undoBlocks = []; foreach($this->blocks as $block) { - if($block->getId() !== Item::AIR) { + if($block->getId() === Item::AIR) { $directions = [ $block->getSide(Block::SIDE_NORTH), $block->getSide(Block::SIDE_SOUTH), $block->getSide(Block::SIDE_WEST), $block->getSide(Block::SIDE_EAST) ]; - + $valid = 0; foreach($directions as $direction) { - if($this->level->getBlock($direction)->getId() === Item::AIR) { - $undoBlocks[] = $direction; + if($this->level->getBlock($direction)->getId() !== Item::AIR) { + $valid++; } } + if($valid >= 2) { + $undoBlocks[] = $block; + } } } foreach($undoBlocks as $selectedBlock) { diff --git a/src/Sandertv/BlockSniper/brush/types/FlattenType.php b/src/Sandertv/BlockSniper/brush/types/FlattenType.php index 80f95497..adb3fd9d 100644 --- a/src/Sandertv/BlockSniper/brush/types/FlattenType.php +++ b/src/Sandertv/BlockSniper/brush/types/FlattenType.php @@ -17,11 +17,11 @@ class FlattenType extends BaseType { public $player; public $center; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = [], Vector3 $center) { + public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->center = $center; + $this->center = $player->getTargetBlock(100); $this->player = $player; } diff --git a/src/Sandertv/BlockSniper/brush/types/LayerType.php b/src/Sandertv/BlockSniper/brush/types/LayerType.php index 111e8f79..6bfa274b 100644 --- a/src/Sandertv/BlockSniper/brush/types/LayerType.php +++ b/src/Sandertv/BlockSniper/brush/types/LayerType.php @@ -16,10 +16,10 @@ class LayerType extends BaseType { public $center; public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = [], Vector3 $center = null) { + public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; - $this->center = $center; + $this->center = $player->getTargetBlock(100); $this->blocks = $blocks; $this->player = $player; diff --git a/src/Sandertv/BlockSniper/brush/types/LeafBlowerType.php b/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php similarity index 94% rename from src/Sandertv/BlockSniper/brush/types/LeafBlowerType.php rename to src/Sandertv/BlockSniper/brush/types/LeafblowerType.php index ec2ee1c9..dc602d8b 100644 --- a/src/Sandertv/BlockSniper/brush/types/LeafBlowerType.php +++ b/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php @@ -10,13 +10,13 @@ use Sandertv\BlockSniper\brush\BaseType; use Sandertv\BlockSniper\Loader; -class LeafBlowerType extends BaseType { +class LeafblowerType extends BaseType { public $level; public $player; public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { + public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; $this->player = $player; diff --git a/src/Sandertv/BlockSniper/brush/types/RaiseType.php b/src/Sandertv/BlockSniper/brush/types/RaiseType.php new file mode 100644 index 00000000..fe12ecd5 --- /dev/null +++ b/src/Sandertv/BlockSniper/brush/types/RaiseType.php @@ -0,0 +1,59 @@ +level = $level; + $this->blocks = $blocks; + + $this->player = $player; + } + + /** + * @return bool + */ + public function fillShape(): bool { + $savedBlocks = []; + $undoBlocks = []; + foreach($this->blocks as $block) { + if($block->getSide(Block::SIDE_UP)->getId() === Block::AIR && $block->getId() !== Block::AIR) { + $savedBlocks[] = $block; + } + } + foreach($savedBlocks as $selectedBlock) { + $undoBlocks[] = $selectedBlock->getSide(Block::SIDE_UP); + $this->level->setBlock($selectedBlock->getSide(Block::SIDE_UP), $selectedBlock, false, false); + } + $this->getMain()->getUndoStore()->saveUndo($undoBlocks); + return true; + } + + public function getName(): string { + return "Raise"; + } + + public function getPermission(): string { + return "blocksniper.type.raise"; + } + + public function getApproximateBlocks(): int { + // TODO + } + + public function getLevel(): Level { + return $this->level; + } +} diff --git a/src/Sandertv/BlockSniper/cloning/BaseClone.php b/src/Sandertv/BlockSniper/cloning/BaseClone.php index 6418fb7b..cd771718 100644 --- a/src/Sandertv/BlockSniper/cloning/BaseClone.php +++ b/src/Sandertv/BlockSniper/cloning/BaseClone.php @@ -15,6 +15,19 @@ public function __construct(Loader $owner) { $this->owner = $owner; } + /** + * @param string $type + * + * @return bool + */ + public static function isCloneType(string $type): bool { + $cloneTypeConst = strtoupper("type_" . $type); + if(defined("self::$cloneTypeConst")) { + return true; + } + return false; + } + public abstract function getName(): string; public abstract function getPermission(): string; diff --git a/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php b/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php index 7523caf0..1b15d387 100644 --- a/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php +++ b/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php @@ -9,7 +9,7 @@ class BlockSniperCommand extends BaseCommand { public function __construct(Loader $owner) { - parent::__construct($owner, "blocksniper", "Get information or change things related to BlockSniper", "[language] [lang]", ["bs"]); + parent::__construct($owner, "blocksniper", "Get information or change things related to BlockSniper", "[language|reload] [lang]", ["bs"]); $this->setPermission("blocksniper.command.undo"); } @@ -40,6 +40,11 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.language")); return true; + case "reload": + $sender->sendMessage(TF::GREEN . "Reloading..."); + $this->getPlugin()->reloadAll(); + return true; + default: $sender->sendMessage(TF::AQUA . "[BlockSniper] Information\n" . TF::GREEN . "Version: " . TF::YELLOW . Loader::VERSION . "\n" . diff --git a/src/Sandertv/BlockSniper/commands/BrushCommand.php b/src/Sandertv/BlockSniper/commands/BrushCommand.php index e07c91b8..c23410ed 100644 --- a/src/Sandertv/BlockSniper/commands/BrushCommand.php +++ b/src/Sandertv/BlockSniper/commands/BrushCommand.php @@ -6,9 +6,11 @@ use pocketmine\level\generator\biome\Biome; use pocketmine\Player; use pocketmine\utils\TextFormat as TF; +use Sandertv\BlockSniper\brush\BaseShape; +use Sandertv\BlockSniper\brush\BaseType; use Sandertv\BlockSniper\brush\Brush; -use Sandertv\BlockSniper\Loader; use Sandertv\BlockSniper\events\ChangeBrushPropertiesEvent as Change; +use Sandertv\BlockSniper\Loader; class BrushCommand extends BaseCommand { @@ -43,6 +45,10 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.radius-not-numeric")); return true; } + if($args[1] > $this->getPlugin()->getSettings()->get("Maximum-Radius")) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.radius-too-big")); + return true; + } Brush::setSize($sender, $args[1]); $sender->sendMessage(TF::GREEN . "Size: " . TF::AQUA . $args[1]); $action = Change::ACTION_CHANGE_SIZE; @@ -50,54 +56,32 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { case "sh": case "shape": - switch(strtolower($args[1])) { - case "cube": - case "sphere": - case "cuboid": - case "cylinder": - if(!$sender->hasPermission("blocksniper.shape." . $args[1])) { - $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.no-permission")); - return true; - } - Brush::setShape($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Shape: " . TF::AQUA . Brush::getShape($sender)->getName()); - $action = Change::ACTION_CHANGE_SHAPE; - break; - - default: - $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.shape-not-found")); - return true; + if(!BaseShape::isShape($args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.shape-not-found")); + return true; } + if(!$sender->hasPermission("blocksniper.shape." . $args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.no-permission")); + return true; + } + Brush::setShape($sender, $args[1]); + $sender->sendMessage(TF::GREEN . "Shape: " . TF::AQUA . Brush::getShape($sender)->getName()); + $action = Change::ACTION_CHANGE_SHAPE; break; case "ty": case "type": - switch(strtolower($args[1])) { - case "fill": - case "clean": - case "cleanentities": - case "drain": - case "flatten": - case "layer": - case "leafblower": - case "overlay": - case "replace": - case "expand": - case "melt": - case "biome": - if(!$sender->hasPermission("blocksniper.type." . $args[1])) { - $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.no-permission")); - return true; - } - Brush::setType($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Type: " . TF::AQUA . Brush::getType($sender)->getName()); - $action = Change::ACTION_CHANGE_TYPE; - break; - - default: - $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.shape-not-found")); - return true; + if(!BaseType::isType($args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.shape-not-found")); + return true; + } + if(!$sender->hasPermission("blocksniper.type." . $args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.no-permission")); + return true; } + Brush::setType($sender, $args[1]); + $sender->sendMessage(TF::GREEN . "Type: " . TF::AQUA . Brush::getType($sender)->getName()); + $action = Change::ACTION_CHANGE_TYPE; break; case "he": @@ -158,7 +142,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { case "biome": $biome = array_slice($args, 1); Brush::setBiome($sender, implode(" ", $biome)); - $sender->sendMessage(TF::GREEN . "Biome: " . TF::AQUA . Biome::getBiome(Brush::getBiomeIdFromString($sender))->getName()); + $sender->sendMessage(TF::GREEN . "Biome: " . TF::AQUA . Biome::getBiome(Brush::getBiomeId($sender))->getName()); $action = Change::ACTION_CHANGE_BIOME; break; @@ -166,7 +150,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { $sender->sendMessage(TF::RED . "[Usage] /brush "); return true; } - $this->getPlugin()->getServer()->getPluginManager()->callEvent(new Change($this->getPlugin(), $sender, $action)); + $this->getPlugin()->getServer()->getPluginManager()->callEvent(new Change($this->getPlugin(), $sender, $action, $args[0])); return true; } } diff --git a/src/Sandertv/BlockSniper/commands/UndoCommand.php b/src/Sandertv/BlockSniper/commands/UndoCommand.php index b0936e45..1a6eb63f 100644 --- a/src/Sandertv/BlockSniper/commands/UndoCommand.php +++ b/src/Sandertv/BlockSniper/commands/UndoCommand.php @@ -37,8 +37,16 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } - $this->getPlugin()->getUndoStore()->restoreLastUndo(); - $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.undo")); + $undoAmount = 1; + if(is_numeric($args[0])) { + $undoAmount = $args[0]; + if($undoAmount > ($totalUndo = $this->getPlugin()->getUndoStore()->getTotalUndoStores())) { + $undoAmount = $totalUndo; + } + } + + $this->getPlugin()->getUndoStore()->restoreLastUndo($undoAmount); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.undo") . TF::AQUA . " (" . $undoAmount . ")"); return true; } } diff --git a/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php b/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php index dacbc656..7e8e6f56 100644 --- a/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php +++ b/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php @@ -2,8 +2,8 @@ namespace Sandertv\BlockSniper\events; -use pocketmine\Player; use pocketmine\event\plugin\PluginEvent; +use pocketmine\Player; use Sandertv\BlockSniper\Loader; class ChangeBrushPropertiesEvent extends PluginEvent { @@ -23,16 +23,18 @@ class ChangeBrushPropertiesEvent extends PluginEvent { public $owner; public $player; public $action; + public $value; - public function __construct(Loader $owner, Player $player, int $action) { + public function __construct(Loader $owner, Player $player, int $action, $value) { parent::__construct($owner); $this->owner = $owner; $this->player = $player; $this->action = $action; + $this->value = $value; } /** - * Returns the player that changed their brush. + * Returns the player that changed their Brush. * * @return Player */ @@ -41,11 +43,20 @@ public function getPlayer(): Player { } /** - * Returns the action of the change. + * Returns the action of the modification. * * @return int */ public function getAction(): int { return $this->action; } + + /** + * Returns the input arguments from the Brush modification. + * + * @return mixed + */ + public function getActionValue() { + return $this->value; + } } \ No newline at end of file diff --git a/src/Sandertv/BlockSniper/listeners/EventListener.php b/src/Sandertv/BlockSniper/listeners/EventListener.php index f3f130df..0bd2b4ef 100644 --- a/src/Sandertv/BlockSniper/listeners/EventListener.php +++ b/src/Sandertv/BlockSniper/listeners/EventListener.php @@ -5,6 +5,7 @@ use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\utils\TextFormat as TF; +use pocketmine\Player; use Sandertv\BlockSniper\brush\Brush; use Sandertv\BlockSniper\events\BrushUseEvent; use Sandertv\BlockSniper\Loader; @@ -23,7 +24,7 @@ public function brush(PlayerInteractEvent $event) { if($player->hasPermission("blocksniper.command.brush")) { $center = $player->getTargetBlock(100); - if(!$center) { + if($center === null) { $player->sendMessage(TF::RED . "[Warning] " . $this->getOwner()->getTranslation("commands.errors.no-target-found")); return false; } @@ -39,6 +40,7 @@ public function brush(PlayerInteractEvent $event) { $type = Brush::getType($player, $shape->getBlocksInside()); $type->fillShape(); + $this->decrementBrush($player); return true; } } @@ -51,8 +53,12 @@ public function getOwner(): Loader { return $this->owner; } - public function decrementBrush(BrushUseEvent $event) { - $player = $event->getPlayer(); + /** + * @param Player $player + * + * @return bool + */ + public function decrementBrush(Player $player): bool { if(Brush::isDecrementing($player)) { if(Brush::getSize($player) <= 1) { if($this->getOwner()->getSettings()->get("Reset-Decrement-Brush") !== false) {