diff --git a/.gitignore b/.gitignore index 106cfd15..485dee64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -/nbproject/private/ -/nbproject/project.properties -/nbproject/project.xml \ No newline at end of file +.idea diff --git a/README.md b/README.md index 628bf6d3..f4e63cfc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ An innovative world editing tool, made for PocketMine-MP: An MCPE server software written in PHP. Worlds can be easily edited using a Golden Carrot, which is used as brush. Find more information about BlockSniper and on how to use it at the [Wiki](https://github.com/Sandertv/BlockSniper/wiki). > Third party versions, forks or spoons of PocketMine are **not** supported. -> +> > Issues related to other server softwares will be closed immediately. ## Installation diff --git a/plugin.yml b/plugin.yml index 6525f49a..6428ee6b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ --- name: "BlockSniper" -version: 1.2.1 -api: [2.0.0, 2.1.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3] +version: 1.3.0 +api: [2.0.0, 2.1.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3, 3.0.0-ALPHA4] author: "Sandertv" main: Sandertv\BlockSniper\Loader @@ -57,6 +57,9 @@ permissions: blocksniper.type.flatten: default: op description: "Allows access to the flatten type" + blocksniper.type.flattenall: + default: op + description: "Allows access to the flatten all type" blocksniper.type.expand: default: op description: "Allows access to the expand type" diff --git a/resources/languages/de.yml b/resources/languages/de.yml index d15abc6d..5984a8ef 100644 --- a/resources/languages/de.yml +++ b/resources/languages/de.yml @@ -16,14 +16,36 @@ commands: clone-not-found: "Dieser Klontyp (clone type) konnte nicht gefunden werden." name-not-set: "Kein gültiger Name wurde festgelegt." template-not-existing: "Es gibt keine Vorlage mit diesem Namen." + preset-already-exists: "That preset already exists." + preset-doesnt-exist: "That preset doesn't exist." succeed: default: "Die Form wurde erfolgreich dort begonnen, wo du hingesehen hast." undo: "Die letzte Modifikation wurde erfolgreich rückgängig gemacht." language: "Sprache wurde erfolgreich geändert." paste: "Klon wurde erfolgreich eingefügt." clone: "Bereich wurde erfolgreich geklont und kopiert." + brush: + reset: "Der Pinsel wurde erfolgreich zurückgesetzt." + preset: + name: "Preset creation process started. Type a name in the chat," + cancel: "or type 'cancel' to cancel the process." + canceled: "Preset creation has been canceled." brushwand: disable: "Brushwand (Zauberpinsel) wurde deaktiviert." enable: "Brushwand (Zauberpinsel) wurde aktiviert." + +brush: + shape: "Form: " + type: "Typ: " + blocks: "Blöcke: " + size: "Größe: " + perfect: "Perfekt: " + obsolete: "Zu ersetzender Block: " + height: "Höhe: " + gravity: "Gravitation: " + decrement: "Verringern: " + biome: "Biom: " + hollow: "Hohl: " + preset: "Preset: " ... diff --git a/resources/languages/en.yml b/resources/languages/en.yml index 7d679bec..9aee7889 100644 --- a/resources/languages/en.yml +++ b/resources/languages/en.yml @@ -16,14 +16,36 @@ commands: clone-not-found: "That clone type could not be found." name-not-set: "No valid name has been given." template-not-existing: "A template with that name does not exist." + preset-already-exists: "That preset already exists." + preset-doesnt-exist: "That preset doesn't exist." succeed: default: "Successfully launched the shape at the location looked at." undo: "Successfully undid the last modification." language: "Language has been changed successfully." paste: "Pasted the clone successfully." clone: "Area has been cloned and copied successfully." + brush: + reset: "Brush has been reset successfully." + preset: + name: "Preset creation process started. Type a name in the chat," + cancel: "or type 'cancel' to cancel the process." + canceled: "Preset creation has been canceled." brushwand: disable: "Brushwand has been disabled." enable: "Brushwand has been enabled." + +brush: + shape: "Shape: " + type: "Type: " + blocks: "Blocks: " + size: "Size: " + perfect: "Perfect: " + obsolete: "Obsolete: " + height: "Height: " + gravity: "Gravity: " + decrement: "Decrement: " + biome: "Biome: " + hollow: "Hollow: " + preset: "Preset: " ... \ No newline at end of file diff --git a/resources/languages/fa.yml b/resources/languages/fa.yml index 25338033..e5551b15 100644 --- a/resources/languages/fa.yml +++ b/resources/languages/fa.yml @@ -15,13 +15,36 @@ commands: no-valid-block: "Block yaft nashod, ID/name block ra benevisid." shape-not-found: "Shekl ya Type yaft nashod." no-modifications: "Shoma hich taghiri anjam nadadid ke Undo konid." + preset-already-exists: "That preset already exists." + preset-doesnt-exist: "That preset doesn't exist." succeed: paste: "Clone paste shode." clone: "Clone ba movafaghit anjam shod." default: "Shape ba movafaghiat lunch shod." undo: "Taghir Undo shod." language: "Zaban Morede Nazar Be Farsi(Persian) Taghir Yaft." + brush: + reset: "Brush has been reset successfully." + preset: + name: "Preset creation process started. Type a name in the chat," + cancel: "or type 'cancel' to cancel the process." + canceled: "Preset creation has been canceled." + brushwand: disable: "Brushwand ghirefaal shod." enable: "Brushwand faal shod." + +brush: + shape: "Shape: " + type: "Type: " + blocks: "Blocks: " + size: "Size: " + perfect: "Perfect: " + obsolete: "Obsolete: " + height: "Height: " + gravity: "Gravity: " + decrement: "Decrement: " + biome: "Biome: " + hollow: "Hollow: " + preset: "Preset: " ... diff --git a/resources/languages/fr.yml b/resources/languages/fr.yml index d30e42a4..f009c106 100644 --- a/resources/languages/fr.yml +++ b/resources/languages/fr.yml @@ -16,15 +16,36 @@ commands: name-not-set: "Veuillez donner un nom" paste-not-found: "Copie introuvable" clone-not-found: "Clone introuvable" + preset-already-exists: "That preset already exists." + preset-doesnt-exist: "That preset doesn't exist." succeed: default: "La forme a été ajoutée avec succès" undo: "Annulé avec succès" language: "La langue a été changé" paste: "Collage effectué avec succès" clone: "Clone réalisé avec succès" - + brush: + reset: "Le pinceau a été réinitialisé avec succès" + preset: + name: "Preset creation process started. Type a name in the chat," + cancel: "or type 'cancel' to cancel the process." + canceled: "Preset creation has been canceled." brushwand: disable: "Pinceau désactivé" enable: "Pinceau activé" + +brush: + shape: "Couche: " + type: "Type: " + blocks: "Blocs: " + size: "Taille: " + perfect: "Parfait: " + obsolete: "Obsolète: " + height: "Hauteur: " + gravity: "Gravité: " + decrement: "Diminuer: " + biome: "Biome: " + hollow: "Creux: " + preset: "Preset: " ... diff --git a/resources/languages/nl.yml b/resources/languages/nl.yml index 3549df96..7b593c8a 100644 --- a/resources/languages/nl.yml +++ b/resources/languages/nl.yml @@ -16,14 +16,36 @@ commands: clone-not-found: "Dat kloon-type kon niet gevonden worden." name-not-set: "Er is geen naam gegeven." template-not-existing: "Er bestaat geen template met die naam." + preset-already-exists: "Die voorinstellingen bestaan al." + preset-doesnt-exist: "Die voorinstellingen bestaan niet." succeed: default: "Afvuren van vorm geslaagd." undo: "Terugdraaien van vorige modificatie geslaagd." language: "Taal veranderen is geslaagd." paste: "Kloon plakken is geslaagd." clone: "Het kopieëren van de zone is geslaagd." + brush: + reset: "Het resetten van de de verf is geslaagd." + preset: + name: "Voorinstellingen maken gestart. Type een naam in de chat," + cancel: "of type 'cancel' om het proces te stoppen." + canceled: "Voorinstellingen maken afgebroken." brushwand: disable: "Verfstaf is uitgeschakeld." enable: "Verfstaf is ingeschakeld." + +brush: + shape: "Vorm: " + type: "Type: " + blocks: "Blokken: " + size: "Grootte: " + perfect: "Perfect: " + obsolete: "Vervangen: " + height: "Hoogte: " + gravity: "Zwaartekracht: " + decrement: "Verkleinend: " + biome: "Biome: " + hollow: "Hol: " + preset: "Voorinstelling: " ... \ No newline at end of file diff --git a/resources/languages/ro.yml b/resources/languages/ro.yml new file mode 100644 index 00000000..d33a8d55 --- /dev/null +++ b/resources/languages/ro.yml @@ -0,0 +1,51 @@ +# Limba Romana de catre NycuRO + +# Romana: +--- +commands: + errors: + no-permission: "Nu ai permisiunea pentru a face acest lucru." + console-use: "Aceasta comanda nu poate fi executata de consola." + radius-not-numeric: "Raza trebuie sa fie exprimata intr-un numar." + radius-too-big: "Raza este prea mare. Te rog sa introduci un numar mai mic." + no-target-found: "Nici un bloc tinta gasit." + no-valid-block: "Blocul nu a fost gasit. Te rog sa introduci un ID valid." + shape-not-found: "Forma sau alt tip nu a fost gasit." + no-modifications: "Nu se poate gasii o modificare pentru a remedia." + paste-not-found: "Nu se poate gasii o lipire disponibila." + clone-not-found: "Nu poate fi gasita o clona." + name-not-set: "Acest nume nu este valid." + template-not-existing: "Nici un sablon nu a fost gasit cu acest nume." + preset-already-exists: "Acest preset deja exista." + preset-doesnt-exist: "Acest preset nu exista." + succeed: + default: "Ai aruncat/lipit cu succes o forma in locul tinta." + undo: "Ai remediat cu succes lucrarea facuta." + language: "Limba a fost schimbata cu succes." + paste: "Ai lipit clona cu succes." + clone: "Zona a fost clonata cu succes." + brush: + reset: "Brush a fost resetata cu succes." + preset: + name: "Presetarea a inceput. Te rog sa introduci un nume in chat" + cancel: "sau scrie 'cancel' pentru a iesi din proces." + canceled: "Presetarea procesului s-a incheiat." + +brushwand: + disable: "Brushwand este dezactivat." + enable: "Brushwand s-a activat cu succes." + +brush: + shape: "Forme: " + type: "Tipuri: " + blocks: "Blocuri: " + size: "Marime: " + perfect: "Perfect: " + obsolete: "Invechite: " + height: "Inaltime: " + gravity: "Gravitate: " + decrement: "Decrementare: " + biome: "Biome: " + hollow: "Gol: " + preset: "Presetat: " +... diff --git a/resources/languages/ru.yml b/resources/languages/ru.yml index 5b79b34f..e3b19696 100644 --- a/resources/languages/ru.yml +++ b/resources/languages/ru.yml @@ -1,4 +1,4 @@ -# Russian translations, by infomcpe. +# Russian translations, by infomcpe.ru # Russian: --- commands: @@ -13,16 +13,38 @@ commands: no-modifications: "Не найдено модификаций чтобы отметить." paste-not-found: "Такой тип вставки не может быть выполнен." clone-not-found: "Такой тип копирования не модет быть выполнен." - name-not-set: "No valid name has been given." - template-not-existing: "A template with that name does not exist." + name-not-set: "Не указано действительное имя." + template-not-existing: "Шаблон с этим именем не существует." + preset-already-exists: "Этот предустановка уже существует." + preset-doesnt-exist: "Предустановка не найдена." succeed: default: "Успешно создано." undo: "Успешно удалена последния модификациия" language: "Смена языка удалась." paste: "Установка скопированой территории удалась." clone: "Територия была скопирована успешно." + brush: + reset: "Кисть успешно сброшена." + preset: + name: "Запустился процесс создания предустановки. Введите имя в чате," + cancel: "или введите «cancel», чтобы отменить процесс." + canceled: "Создание предустановки отменено." brushwand: disable: "Brushwand Отключен" enable: "Brushwand Включён." + +brush: + shape: "Форма: " + type: "Тип: " + blocks: "Блоки: " + size: "Размер: " + perfect: "Отлично: " + obsolete: "Устарел: " + height: "Высота: " + gravity: "Сила тяжести: " + decrement: "Уменьшение: " + biome: "Биом: " + hollow: "Полый: " + preset: "Предустановка: " ... diff --git a/resources/languages/zh_tw.yml b/resources/languages/zh_tw.yml index 44491bcc..b0044226 100644 --- a/resources/languages/zh_tw.yml +++ b/resources/languages/zh_tw.yml @@ -16,14 +16,36 @@ commands: clone-not-found: "該模型模式未找到" name-not-set: "名稱未設置" template-not-existing: "未找到該名稱的模型模板" + preset-already-exists: "That preset already exists." + preset-doesnt-exist: "That preset doesn't exist." succeed: default: "成功在自身座標上建立形狀" undo: "成功還原先前動作" language: "成功改變語言檔案" paste: "成功複製模型" clone: "該範圍的模型成功建立" + brush: + reset: "Brush has been reset successfully." + preset: + name: "Preset creation process started. Type a name in the chat," + cancel: "or type 'cancel' to cancel the process." + canceled: "Preset creation has been canceled." brushwand: disable: "刷子功能成功關閉" enable: "刷子功能成功開啟" + +brush: + shape: "Shape: " + type: "Type: " + blocks: "Blocks: " + size: "Size: " + perfect: "Perfect: " + obsolete: "Obsolete: " + height: "Height: " + gravity: "Gravity: " + decrement: "Decrement: " + biome: "Biome: " + hollow: "Hollow: " + preset: "Preset: " ... \ No newline at end of file diff --git a/resources/settings.yml b/resources/settings.yml index 09643a69..7fabcaaa 100644 --- a/resources/settings.yml +++ b/resources/settings.yml @@ -11,6 +11,9 @@ Brush-Item: 396 # Maximum radius for shapes/types, it is recommended to keep this number below 20 to prevent server freezes and lag. Maximum-Radius: 15 +# Maximum radius/height for clones, it is recommended to keep this number below 60 to prevent server freezes and lag. +Maximum-Clone-Size: 60 + # 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: 15 diff --git a/src/Sandertv/BlockSniper/Loader.php b/src/Sandertv/BlockSniper/Loader.php index a0f7fc92..a41a7030 100644 --- a/src/Sandertv/BlockSniper/Loader.php +++ b/src/Sandertv/BlockSniper/Loader.php @@ -3,7 +3,6 @@ namespace Sandertv\BlockSniper; use pocketmine\plugin\PluginBase; -use pocketmine\utils\Config; use pocketmine\utils\TextFormat as TF; use Sandertv\BlockSniper\brush\Brush; use Sandertv\BlockSniper\cloning\CloneStorer; @@ -12,19 +11,23 @@ use Sandertv\BlockSniper\commands\cloning\CloneCommand; use Sandertv\BlockSniper\commands\cloning\PasteCommand; use Sandertv\BlockSniper\commands\UndoCommand; -use Sandertv\BlockSniper\data\TranslationData; -use Sandertv\BlockSniper\listeners\EventListener; use Sandertv\BlockSniper\data\ConfigData; +use Sandertv\BlockSniper\data\TranslationData; +use Sandertv\BlockSniper\listeners\BrushListener; +use Sandertv\BlockSniper\listeners\PresetListener; +use Sandertv\BlockSniper\presets\PresetManager; +use Sandertv\BlockSniper\tasks\UndoDiminishTask; class Loader extends PluginBase { - const VERSION = "1.2.1"; - const API_TARGET = "2.0.0 - 3.0.0-ALPHA3"; + const VERSION = "1.3.0"; + const API_TARGET = "2.0.0 - 3.0.0-ALPHA4"; public $undoStore; public $cloneStore; public $settings; public $brush; + public $presetManager; public $availableLanguages = [ "en", @@ -41,7 +44,9 @@ public function onEnable() { $this->reloadAll(); $this->registerCommands(); - $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); + $this->registerListeners(); + + $this->getServer()->getScheduler()->scheduleRepeatingTask(new UndoDiminishTask($this), 400); } public function reloadAll() { @@ -51,6 +56,8 @@ public function reloadAll() { $this->brush = new Brush($this); $this->undoStore = new UndoStorer($this); $this->cloneStore = new CloneStorer($this); + + $this->presetManager = new PresetManager($this); if(!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } @@ -72,7 +79,7 @@ public function reloadAll() { } /** - * @return Config + * @return ConfigData */ public function getSettings(): ConfigData { return $this->settings; @@ -91,9 +98,20 @@ public function registerCommands() { } } + public function registerListeners() { + $blockSniperListeners = [ + new BrushListener($this), + new PresetListener($this), + ]; + foreach($blockSniperListeners as $listener) { + $this->getServer()->getPluginManager()->registerEvents($listener, $this); + } + } + public function onDisable() { $this->getLogger()->info(TF::RED . "BlockSniper has been disabled."); $this->getUndoStore()->resetUndoStorage(); + $this->getPresetManager()->storePresetsToFile(); } /** @@ -103,22 +121,26 @@ public function getUndoStore(): UndoStorer { return $this->undoStore; } + public function getPresetManager(): PresetManager { + return $this->presetManager; + } + + /** + * @return CloneStorer + */ + public function getCloneStore(): CloneStorer { + return $this->cloneStore; + } + /** * @param string $message * - * @return string + * @return string|null */ public function getTranslation(string $message): string { if($this->language instanceof TranslationData) { return $this->language->get($message); } - } - - - /** - * @return CloneStorer - */ - public function getCloneStore(): CloneStorer { - return $this->cloneStore; + return null; } } diff --git a/src/Sandertv/BlockSniper/UndoStorer.php b/src/Sandertv/BlockSniper/UndoStorer.php index 63b56c76..df74f09c 100644 --- a/src/Sandertv/BlockSniper/UndoStorer.php +++ b/src/Sandertv/BlockSniper/UndoStorer.php @@ -4,7 +4,6 @@ use pocketmine\item\Item; use pocketmine\math\Vector3; -use Sandertv\BlockSniper\tasks\UndoDiminishTask; class UndoStorer { @@ -36,11 +35,17 @@ public function saveUndo(array $blocks) { if($this->getTotalUndoStores() === $this->getOwner()->getSettings()->get("Maximum-Undo-Stores")) { $this->unsetFirstUndo(); } - $this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask(new UndoDiminishTask($this->getOwner()), 2400); $this->lastUndo = time(); } + /** + * @return int + */ + public function getTotalUndoStores(): int { + return count($this->undoStore); + } + /** * @return Loader */ @@ -102,11 +107,4 @@ 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 cc30f964..e74b42b4 100644 --- a/src/Sandertv/BlockSniper/brush/BaseShape.php +++ b/src/Sandertv/BlockSniper/brush/BaseShape.php @@ -2,6 +2,13 @@ namespace Sandertv\BlockSniper\brush; +use pocketmine\level\Level; +use pocketmine\level\Position; +use pocketmine\Player; +use Sandertv\BlockSniper\brush\shapes\CubeShape; +use Sandertv\BlockSniper\brush\shapes\CuboidShape; +use Sandertv\BlockSniper\brush\shapes\CylinderShape; +use Sandertv\BlockSniper\brush\shapes\SphereShape; use Sandertv\BlockSniper\Loader; abstract class BaseShape { @@ -14,6 +21,15 @@ abstract class BaseShape { const SHAPE_CYLINDER = 2; const SHAPE_CUBOID = 3; + public $level; + public $player; + public $main; + protected $width; + protected $radius; + protected $center; + protected $hollow; + protected $height; + public function __construct(Loader $main) { $this->main = $main; } @@ -58,7 +74,81 @@ public abstract function getPermission(): string; public abstract function getBlocksInside(): array; + public abstract function getApproximateProcessedBlocks(): int; + public function getMain(): Loader { return $this->main; } + + /** + * Returns the level the shape is made in. + * + * @return Level + */ + public function getLevel(): Level { + return $this->level; + } + + /** + * Returns the player that made the shape. + * + * @return Player + */ + public function getPlayer(): Player { + return $this->player; + } + + /** + * Returns the width in case of a CubeShape or CuboidShape. + * + * @return float + */ + public function getWidth(): float { + if($this instanceof CubeShape || $this instanceof CuboidShape) { + return $this->width; + } + return null; + } + + /** + * Returns the radius in case of a SphereShape or CylinderShape. + * + * @return float|null + */ + public function getRadius(): int { + if($this instanceof SphereShape || $this instanceof CylinderShape) { + return $this->radius; + } + return null; + } + + /** + * Returns the center of the shape made, or the target block. + * + * @return Position + */ + public function getCenter(): Position { + return $this->center; + } + + /** + * Returns true if the shape is hollow, false if it is not. + * + * @return bool + */ + public function getHollow(): bool { + return $this->hollow; + } + + /** + * Returns the height in case of a CylinderShape or CuboidShape. + * + * @return int|null + */ + public function getHeight(): int { + if($this instanceof CylinderShape || $this instanceof CuboidShape) { + return $this->height; + } + return null; + } } diff --git a/src/Sandertv/BlockSniper/brush/BaseType.php b/src/Sandertv/BlockSniper/brush/BaseType.php index 3dd2b1c0..ed7a1d29 100644 --- a/src/Sandertv/BlockSniper/brush/BaseType.php +++ b/src/Sandertv/BlockSniper/brush/BaseType.php @@ -2,6 +2,14 @@ namespace Sandertv\BlockSniper\brush; +use pocketmine\level\Level; +use pocketmine\level\Position; +use pocketmine\Player; +use Sandertv\BlockSniper\brush\types\BiomeType; +use Sandertv\BlockSniper\brush\types\FlattenallType; +use Sandertv\BlockSniper\brush\types\FlattenType; +use Sandertv\BlockSniper\brush\types\LayerType; +use Sandertv\BlockSniper\brush\types\ReplaceType; use Sandertv\BlockSniper\Loader; abstract class BaseType { @@ -14,16 +22,23 @@ abstract class BaseType { const TYPE_LAYER = 2; const TYPE_REPLACE = 3; const TYPE_FLATTEN = 4; - const TYPE_DRAIN = 5; - const TYPE_LEAFBLOWER = 6; - const TYPE_CLEAN = 7; - const TYPE_BIOME = 8; - const TYPE_CLEANENTITIES = 9; - const TYPE_MELT = 10; - const TYPE_EXPAND = 11; - const TYPE_RAISE = 12; + const TYPE_FLATTENALL = 5; + const TYPE_DRAIN = 6; + const TYPE_LEAFBLOWER = 7; + const TYPE_CLEAN = 8; + const TYPE_BIOME = 9; + const TYPE_CLEANENTITIES = 10; + const TYPE_MELT = 11; + const TYPE_EXPAND = 12; + const TYPE_RAISE = 13; + public $level; + public $player; public $main; + protected $biome; + protected $blocks; + protected $center; + protected $obsolete; public function __construct(Loader $main) { $this->main = $main; @@ -69,7 +84,73 @@ public abstract function getPermission(): string; public abstract function fillShape(): bool; + /** + * @return Loader + */ public function getMain(): Loader { return $this->main; } + + /** + * Returns the level the type is used in. + * + * @return Level + */ + public function getLevel(): Level { + return $this->level; + } + + /** + * Returns the player that used the type. + * + * @return Player + */ + public function getPlayer(): Player { + return $this->player; + } + + /** + * Returns the biome ID in case of a BiomeType + * + * @return int|null + */ + public function getBiome(): int { + if($this instanceof BiomeType) { + return $this->biome; + } + return null; + } + + /** + * Returns the blocks the type is being executed upon. + * + * @return array + */ + public function getBlocks(): array { + return $this->blocks; + } + + /** + * Returns the center in case of a Flatten- or LayerType. + * + * @return Position|null + */ + public function getCenter(): Position { + if($this instanceof FlattenType || $this instanceof FlattenallType || $this instanceof LayerType) { + return $this->center; + } + return null; + } + + /** + * Returns the obsolete blocks in case of a ReplaceType. + * + * @return array|null + */ + public function getObsolete(): array { + if($this instanceof ReplaceType) { + return $this->obsolete; + } + return null; + } } diff --git a/src/Sandertv/BlockSniper/brush/Brush.php b/src/Sandertv/BlockSniper/brush/Brush.php index 0bbb32a4..7a1a5f82 100644 --- a/src/Sandertv/BlockSniper/brush/Brush.php +++ b/src/Sandertv/BlockSniper/brush/Brush.php @@ -34,10 +34,11 @@ public static function setupDefaultValues(Player $player): bool { "size" => 1, "height" => 1, "blocks" => [Block::get(Block::STONE)], - "obsolete" => Block::get(Block::AIR), + "obsolete" => [Block::get(Block::AIR)], "gravity" => false, "decrement" => false, - "biome" => "plains" + "biome" => "plains", + "hollow" => false ]; return true; } @@ -111,18 +112,25 @@ public static function getPerfect(Player $player): bool { /** * @param Player $player * - * @return Block + * @return array */ - public static function getObsolete(Player $player): Block { + public static function getObsolete(Player $player): array { return self::$brush[$player->getId()]["obsolete"]; } /** * @param Player $player - * @param $block + * @param array $blocks */ - public static function setObsolete(Player $player, $block) { - self::$brush[$player->getId()]["obsolete"] = (is_numeric($block) ? Item::get($block)->getBlock() : Item::fromString($block)->getBlock()); + public static function setObsolete(Player $player, array $blocks) { + unset(self::$brush[$player->getId()]["obsolete"]); + foreach($blocks as $block) { + if(!is_numeric($block)) { + self::$brush[$player->getId()]["obsolete"][] = Item::fromString($block)->getBlock(); + } else { + self::$brush[$player->getId()]["obsolete"][] = Item::get($block)->getBlock(); + } + } } /** @@ -173,7 +181,7 @@ public static function setShape(Player $player, string $shape) { */ public static function getShape(Player $player): BaseShape { $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)); + $shape = new $shapeName(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100), self::getHollow($player)); return $shape; } @@ -187,6 +195,15 @@ public static function getSize(Player $player): int { return self::$brush[$player->getId()]["size"]; } + /** + * @param Player $player + * + * @return bool + */ + public static function getHollow(Player $player): bool { + return self::$brush[$player->getId()]["hollow"]; + } + /** * @param Player $player * @@ -211,13 +228,21 @@ public static function getType(Player $player, array $blocks = []): BaseType { /** * @param Player $player - * @param string $biome + * @param mixed $biome */ - public static function setBiome(Player $player, string $biome) { + public static function setBiome(Player $player, $biome) { self::$brush[$player->getId()]["biome"] = $biome; } + /** + * @param Player $player + * + * @return int + */ public static function getBiomeId(Player $player): int { + if(is_numeric(self::$brush[$player->getId()]["biome"])) { + return self::$brush[$player->getId()]["biome"]; + } $biomes = new ReflectionClass('pocketmine\level\generator\biome\Biome'); $const = strtoupper(str_replace(" ", "_", self::$brush[$player->getId()]["biome"])); if($biomes->hasConstant($const)) { @@ -226,4 +251,25 @@ public static function getBiomeId(Player $player): int { } return 0; } + + /** + * @param Player $player + * + * @return bool + */ + public static function resetBrush(Player $player): bool { + if(isset(self::$brush[$player->getId()])) { + unset(self::$brush[$player->getId()]); + return true; + } + return false; + } + + /** + * @param Player $player + * @param $value + */ + public static function setHollow(Player $player, $value) { + self::$brush[$player->getId()]["hollow"] = (bool)$value; + } } \ No newline at end of file diff --git a/src/Sandertv/BlockSniper/brush/shapes/CubeShape.php b/src/Sandertv/BlockSniper/brush/shapes/CubeShape.php index 3d6b2c2e..8fcd91f5 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/CubeShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/CubeShape.php @@ -12,17 +12,13 @@ class CubeShape extends BaseShape { - public $level; - public $radius; - public $center; - public $player; - - public function __construct(Loader $main, Player $player, Level $level, float $radius = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, int $width = null, Position $center = null, bool $hollow = false) { parent::__construct($main); $this->level = $level; - $this->radius = $radius; + $this->width = $width; $this->center = $center; $this->player = $player; + $this->hollow = $hollow; } /** @@ -33,17 +29,22 @@ public function getBlocksInside(): array { $targetY = $this->center->y; $targetZ = $this->center->z; - $minX = $targetX - $this->radius; - $minZ = $targetZ - $this->radius; - $minY = $targetY - $this->radius; - $maxX = $targetX + $this->radius; - $maxZ = $targetZ + $this->radius; - $maxY = $targetY + $this->radius; + $minX = $targetX - $this->width; + $minZ = $targetZ - $this->width; + $minY = $targetY - $this->width; + $maxX = $targetX + $this->width; + $maxZ = $targetZ + $this->width; + $maxY = $targetY + $this->width; $blocksInside = []; for($x = $minX; $x <= $maxX; $x++) { for($z = $minZ; $z <= $maxZ; $z++) { for($y = $minY; $y <= $maxY; $y++) { + if($this->hollow === true) { + if($x !== $maxX && $x !== $minX && $y !== $maxY && $y !== $minY && $z !== $maxZ && $z !== $minZ) { + continue; + } + } if(Brush::getGravity($this->player) === true || Brush::getGravity($this->player) === 1) { $gravityY = ($this->level->getHighestBlockAt($x, $z) + 1) <= $maxY ? $this->level->getHighestBlockAt($x, $z) + 1 : $y; } @@ -67,15 +68,8 @@ public function getPermission(): string { return "blocksniper.shape.cube"; } - public function getApproximateBlocks(): int { - // TODO - } - - public function getCenter(): Position { - return $this->center; - } - - public function setCenter(Position $center) { - $this->center = $center; + public function getApproximateProcessedBlocks(): int { + $blockCount = abs(($this->center->x - $this->radius) - ($this->center->x + $this->radius)) * abs(($this->center->z - $this->radius) - ($this->center->z + $this->radius)) * abs(($this->center->y - $this->radius) - ($this->center->y + $this->radius)); + return $blockCount; } } diff --git a/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php b/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php index 8682d133..5f45546b 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/CuboidShape.php @@ -12,19 +12,14 @@ class CuboidShape extends BaseShape { - public $level; - public $width; - public $height; - public $center; - public $player; - - public function __construct(Loader $main, Player $player, Level $level, float $width = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, int $width = null, Position $center = null, bool $hollow = false) { parent::__construct($main); $this->level = $level; $this->width = $width; $this->height = Brush::getHeight($player); $this->center = $center; $this->player = $player; + $this->hollow = $hollow; } /** @@ -47,6 +42,11 @@ public function getBlocksInside(): array { for($x = $minX; $x <= $maxX; $x++) { for($y = $minY; $y <= $maxY; $y++) { for($z = $minZ; $z <= $maxZ; $z++) { + if($this->hollow === true) { + if($x !== $maxX && $x !== $minX && $y !== $maxY && $y !== $minY && $z !== $maxZ && $z !== $minZ) { + continue; + } + } if(Brush::getGravity($this->player) === true || Brush::getGravity($this->player) === 1) { $gravityY = ($this->level->getHighestBlockAt($x, $z) + 1) <= $maxY ? $this->level->getHighestBlockAt($x, $z) + 1 : $y; } @@ -70,15 +70,8 @@ public function getPermission(): string { return "blocksniper.shape.cuboid"; } - public function getApproximateBlocks(): int { - // TODO - } - - public function getCenter(): Position { - return $this->center; - } - - public function setCenter(Position $center) { - $this->center = $center; + public function getApproximateProcessedBlocks(): int { + $blockCount = abs(($this->center->x - $this->width) - ($this->center->x + $this->width)) * abs(($this->center->z - $this->width) - ($this->center->z + $this->width)) * abs(($this->center->y - $this->height) - ($this->center->y + $this->height)); + return $blockCount; } } diff --git a/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php b/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php index 098a042a..8d4df203 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/CylinderShape.php @@ -12,19 +12,14 @@ class CylinderShape extends BaseShape { - public $level; - public $radius; - public $height; - public $player; - public $center; - - public function __construct(Loader $main, Player $player, Level $level, float $radius = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, int $radius = null, Position $center = null, bool $hollow = false) { parent::__construct($main); $this->level = $level; $this->radius = $radius; $this->height = Brush::getHeight($player); $this->center = $center; $this->player = $player; + $this->hollow = $hollow; } /** @@ -49,6 +44,11 @@ public function getBlocksInside(): array { for($z = $minZ; $z <= $maxZ; $z++) { for($y = $minY; $y <= $maxY; $y++) { if(pow($targetX - $x, 2) + pow($targetZ - $z, 2) <= $radiusSquared) { + if($this->hollow === true) { + if($y !== $maxY && $y !== $minY && (pow($targetX - $x, 2) + pow($targetZ - $z, 2)) < $radiusSquared - 3 - $this->radius / 0.5) { + continue; + } + } if(Brush::getGravity($this->player) === true || Brush::getGravity($this->player) === 1) { $gravityY = ($this->level->getHighestBlockAt($x, $z) + 1) <= $maxY ? $this->level->getHighestBlockAt($x, $z) + 1 : $y; } @@ -70,18 +70,11 @@ public function getName(): string { } public function getPermission(): string { - return "blocksniper.shape.cylinderstanding"; - } - - public function getApproximateBlocks(): int { - // TODO + return "blocksniper.shape.standingcylinder"; } - public function getCenter(): Position { - return $this->center; - } - - public function setCenter(Position $center) { - $this->center = $center; + public function getApproximateProcessedBlocks(): int { + $blockCount = $this->radius * $this->radius * M_PI * $this->height; + return $blockCount; } } diff --git a/src/Sandertv/BlockSniper/brush/shapes/SphereShape.php b/src/Sandertv/BlockSniper/brush/shapes/SphereShape.php index b1027a56..f6e8d224 100644 --- a/src/Sandertv/BlockSniper/brush/shapes/SphereShape.php +++ b/src/Sandertv/BlockSniper/brush/shapes/SphereShape.php @@ -4,7 +4,6 @@ use pocketmine\level\Level; use pocketmine\level\Position; -use pocketmine\math\Math; use pocketmine\math\Vector3; use pocketmine\Player; use Sandertv\BlockSniper\brush\BaseShape; @@ -13,17 +12,13 @@ class SphereShape extends BaseShape { - public $level; - public $radius; - public $center; - public $player; - - public function __construct(Loader $main, Player $player, Level $level, float $radius = null, Position $center = null) { + public function __construct(Loader $main, Player $player, Level $level, int $radius = null, Position $center = null, bool $hollow = false) { parent::__construct($main); $this->level = $level; $this->radius = $radius; $this->center = $center; $this->player = $player; + $this->hollow = $hollow; } /** @@ -37,12 +32,12 @@ public function getBlocksInside(): array { $targetY = $this->center->y; $targetZ = $this->center->z; - $minX = Math::floorFloat($targetX - $this->radius); - $maxX = Math::floorFloat($targetX + $this->radius) + 1; - $minY = max(Math::floorFloat($targetY - $this->radius), 0); - $maxY = min(Math::floorFloat($targetY + $this->radius) + 1, BaseShape::MAX_WORLD_HEIGHT); - $minZ = Math::floorFloat($targetZ - $this->radius); - $maxZ = Math::floorFloat($targetZ + $this->radius) + 1; + $minX = $targetX - $this->radius; + $minZ = $targetZ - $this->radius; + $minY = $targetY - $this->radius; + $maxX = $targetX + $this->radius; + $maxZ = $targetZ + $this->radius; + $maxY = $targetY + $this->radius; $blocksInside = []; @@ -53,6 +48,11 @@ public function getBlocksInside(): array { for($z = $maxZ; $z >= $minZ; $z--) { $zs = ($targetZ - $z) * ($targetZ - $z); if($xs + $ys + $zs < $radiusSquared) { + if($this->hollow === true) { + if($y !== $maxY && $y !== $minY && ($xs + $ys + $zs) < $radiusSquared - 3 - $this->radius / 0.5) { + continue; + } + } if(Brush::getGravity($this->player) === true || Brush::getGravity($this->player) === 1) { $gravityY = ($this->level->getHighestBlockAt($x, $z) + 1) <= $maxY ? $this->level->getHighestBlockAt($x, $z) + 1 : $y; } @@ -77,31 +77,8 @@ public function getPermission(): string { return "blocksniper.shape.sphere"; } - public function getApproximateBlocks(): int { - // TODO - } - - public function getRadius(): float { - return $this->radius; - } - - public function setRadius(float $radius) { - $this->radius = $radius; - } - - public function getCenter(): Position { - return $this->center; - } - - public function setCenter(Position $center) { - $this->center = $center; - } - - public function getBlocks(): array { - return $this->blocks; - } - - public function setBlocks(array $blocks) { - $this->blocks = $blocks; + public function getApproximateProcessedBlocks(): int { + $blockCount = 4 / 3 * M_PI * pow($this->radius, 3); + return $blockCount; } } diff --git a/src/Sandertv/BlockSniper/brush/types/BiomeType.php b/src/Sandertv/BlockSniper/brush/types/BiomeType.php index 5f55b60a..6cee6c96 100644 --- a/src/Sandertv/BlockSniper/brush/types/BiomeType.php +++ b/src/Sandertv/BlockSniper/brush/types/BiomeType.php @@ -10,16 +10,12 @@ class BiomeType extends BaseType { - public $level; - public $blocks; - public $player; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; + $this->biome = Brush::getBiomeId($this->player); } /** @@ -27,7 +23,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::getBiomeId($this->player)); + $this->level->setBiomeId($block->x, $block->z, $this->biome); } return true; } @@ -40,10 +36,6 @@ public function getPermission(): string { return "blocksniper.type.biome"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/CleanType.php b/src/Sandertv/BlockSniper/brush/types/CleanType.php index 1a268379..7c4d8169 100644 --- a/src/Sandertv/BlockSniper/brush/types/CleanType.php +++ b/src/Sandertv/BlockSniper/brush/types/CleanType.php @@ -11,15 +11,10 @@ class CleanType extends BaseType { - public $level; - public $blocks; - public $player; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; } @@ -30,7 +25,7 @@ public function fillShape(): bool { $undoBlocks = []; foreach($this->blocks as $block) { $blockId = $block->getId(); - if($blockId !== 0 && $blockId !== 1 && $blockId !== 2 && $blockId !== 3 && $blockId !== 12 && $blockId !== 13 && $blockId !== 24) { + if($blockId !== Block::AIR && $blockId !== Block::STONE && $blockId !== Block::GRASS && $blockId !== Block::DIRT && $blockId !== Block::GRAVEL && $blockId !== Block::SAND && $blockId !== Block::SANDSTONE) { if($blockId !== Block::AIR) { $undoBlocks[] = $block; } @@ -49,10 +44,6 @@ public function getPermission(): string { return "blocksniper.type.clean"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php b/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php index 78112c61..e97b19ba 100644 --- a/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php +++ b/src/Sandertv/BlockSniper/brush/types/CleanentitiesType.php @@ -9,15 +9,10 @@ class CleanentitiesType extends BaseType { - public $level; - public $blocks; - public $player; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; } diff --git a/src/Sandertv/BlockSniper/brush/types/DrainType.php b/src/Sandertv/BlockSniper/brush/types/DrainType.php index 61fb3968..ca8038cb 100644 --- a/src/Sandertv/BlockSniper/brush/types/DrainType.php +++ b/src/Sandertv/BlockSniper/brush/types/DrainType.php @@ -12,15 +12,10 @@ class DrainType extends BaseType { - public $player; - public $level; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; } @@ -48,10 +43,6 @@ public function getPermission(): string { return "blocksniper.type.drain"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/ExpandType.php b/src/Sandertv/BlockSniper/brush/types/ExpandType.php index 0a16739c..b16d9455 100644 --- a/src/Sandertv/BlockSniper/brush/types/ExpandType.php +++ b/src/Sandertv/BlockSniper/brush/types/ExpandType.php @@ -11,10 +11,6 @@ class ExpandType extends BaseType { - public $player; - public $level; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; @@ -62,9 +58,6 @@ public function getPermission(): string { return "blocksniper.type.expand"; } - public function getApproximateBlocks(): int { - // TODO - } public function getLevel(): Level { return $this->level; diff --git a/src/Sandertv/BlockSniper/brush/types/FillType.php b/src/Sandertv/BlockSniper/brush/types/FillType.php index 75997057..059ad9e6 100644 --- a/src/Sandertv/BlockSniper/brush/types/FillType.php +++ b/src/Sandertv/BlockSniper/brush/types/FillType.php @@ -11,15 +11,10 @@ class FillType extends BaseType { - public $level; - public $blocks; - public $player; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; } @@ -45,10 +40,6 @@ public function getPermission(): string { return "blocksniper.type.fill"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/FlattenType.php b/src/Sandertv/BlockSniper/brush/types/FlattenType.php index adb3fd9d..ff38b278 100644 --- a/src/Sandertv/BlockSniper/brush/types/FlattenType.php +++ b/src/Sandertv/BlockSniper/brush/types/FlattenType.php @@ -2,6 +2,7 @@ namespace Sandertv\BlockSniper\brush\types; +use pocketmine\block\Flowable; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -12,17 +13,11 @@ class FlattenType extends BaseType { - public $level; - public $blocks; - public $player; - public $center; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; $this->center = $player->getTargetBlock(100); - $this->player = $player; } @@ -33,7 +28,7 @@ public function fillShape(): bool { $undoBlocks = []; foreach($this->blocks as $block) { $randomBlock = Brush::$brush[$this->player->getId()]["blocks"][array_rand(Brush::$brush[$this->player->getId()]["blocks"])]; - if($block->getId() === Item::AIR && $block->y <= $this->center->y) { + if(($block->getId() === Item::AIR || $block instanceof Flowable) && $block->y <= $this->center->y) { if($block->getId() !== $randomBlock->getId()) { $undoBlocks[] = $block; } @@ -52,10 +47,6 @@ public function getPermission(): string { return "blocksniper.type.flatten"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/FlattenallType.php b/src/Sandertv/BlockSniper/brush/types/FlattenallType.php new file mode 100644 index 00000000..b48dbbf7 --- /dev/null +++ b/src/Sandertv/BlockSniper/brush/types/FlattenallType.php @@ -0,0 +1,58 @@ +level = $level; + $this->blocks = $blocks; + $this->center = $player->getTargetBlock(100); + $this->player = $player; + } + + /** + * @return bool + */ + public function fillShape(): bool { + $undoBlocks = []; + foreach($this->blocks as $block) { + $randomBlock = Brush::$brush[$this->player->getId()]["blocks"][array_rand(Brush::$brush[$this->player->getId()]["blocks"])]; + if(($block->getId() === Item::AIR || $block instanceof Flowable) && $block->y <= $this->center->y) { + if($block->getId() !== $randomBlock->getId()) { + $undoBlocks[] = $block; + } + $this->level->setBlock(new Vector3($block->x, $block->y, $block->z), $randomBlock, false, false); + } + if($block->getId() !== Item::AIR && $block->y > $this->center->y) { + $undoBlocks[] = $block; + $this->level->setBlock($block, Block::get(Block::AIR)); + } + } + $this->getMain()->getUndoStore()->saveUndo($undoBlocks); + return true; + } + + public function getName(): string { + return "Flatten All"; + } + + public function getPermission(): string { + return "blocksniper.type.flattenall"; + } + + public function getLevel(): Level { + return $this->level; + } +} diff --git a/src/Sandertv/BlockSniper/brush/types/LayerType.php b/src/Sandertv/BlockSniper/brush/types/LayerType.php index 6bfa274b..c00661b1 100644 --- a/src/Sandertv/BlockSniper/brush/types/LayerType.php +++ b/src/Sandertv/BlockSniper/brush/types/LayerType.php @@ -11,17 +11,11 @@ class LayerType extends BaseType { - public $player; - public $level; - public $center; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; $this->center = $player->getTargetBlock(100); $this->blocks = $blocks; - $this->player = $player; } @@ -49,10 +43,6 @@ public function getPermission(): string { return "blocksniper.type.layer"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php b/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php index dc602d8b..cb4c4bba 100644 --- a/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php +++ b/src/Sandertv/BlockSniper/brush/types/LeafblowerType.php @@ -12,10 +12,6 @@ class LeafblowerType extends BaseType { - public $level; - public $player; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; @@ -47,10 +43,6 @@ public function getPermission(): string { return "blocksniper.type.leafblower"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/MeltType.php b/src/Sandertv/BlockSniper/brush/types/MeltType.php index 408448d5..20b1228b 100644 --- a/src/Sandertv/BlockSniper/brush/types/MeltType.php +++ b/src/Sandertv/BlockSniper/brush/types/MeltType.php @@ -11,10 +11,6 @@ class MeltType extends BaseType { - public $player; - public $level; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; @@ -64,10 +60,6 @@ public function getPermission(): string { return "blocksniper.type.melt"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/OverlayType.php b/src/Sandertv/BlockSniper/brush/types/OverlayType.php index a22e7f02..0ee94ee5 100644 --- a/src/Sandertv/BlockSniper/brush/types/OverlayType.php +++ b/src/Sandertv/BlockSniper/brush/types/OverlayType.php @@ -12,10 +12,6 @@ class OverlayType extends BaseType { - public $player; - public $level; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks = []) { parent::__construct($main); $this->level = $level; @@ -73,10 +69,6 @@ public function getPermission(): string { return "blocksniper.type.overlay"; } - public function getApproximateBlocks(): int { - // TODO - } - public function getLevel(): Level { return $this->level; } diff --git a/src/Sandertv/BlockSniper/brush/types/RaiseType.php b/src/Sandertv/BlockSniper/brush/types/RaiseType.php index 0b3ce1d1..c85acb38 100644 --- a/src/Sandertv/BlockSniper/brush/types/RaiseType.php +++ b/src/Sandertv/BlockSniper/brush/types/RaiseType.php @@ -2,23 +2,18 @@ namespace Sandertv\BlockSniper\brush\types; +use pocketmine\block\Block; use pocketmine\level\Level; use pocketmine\Player; -use pocketmine\block\Block; use Sandertv\BlockSniper\brush\BaseType; use Sandertv\BlockSniper\Loader; class RaiseType extends BaseType { - public $level; - public $blocks; - public $player; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->blocks = $blocks; - $this->player = $player; } @@ -29,6 +24,7 @@ public function fillShape(): bool { $savedBlocks = []; $holeBlocks = []; $undoBlocks = []; + $peakBlocks = []; $sides = [ Block::SIDE_NORTH, Block::SIDE_EAST, @@ -45,11 +41,18 @@ public function fillShape(): bool { if($valid >= 3) { $holeBlocks[] = $block; } + if($valid === 0) { + $peakBlocks[] = $block; + } } foreach($holeBlocks as $selectedBlock) { $undoBlocks[] = $selectedBlock; $this->level->setBlock($selectedBlock, $this->level->getBlock($selectedBlock->subtract(0, 1)), false, false); } + foreach($peakBlocks as $selectedBlock) { + $undoBlocks[] = $selectedBlock; + $this->level->setBlock($selectedBlock, Block::get(Block::AIR), false, false); + } foreach($this->blocks as $block) { if($block->getSide(Block::SIDE_UP)->getId() === Block::AIR && $block->getId() !== Block::AIR) { $savedBlocks[] = $block; @@ -71,10 +74,6 @@ 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/brush/types/ReplaceType.php b/src/Sandertv/BlockSniper/brush/types/ReplaceType.php index d3b8f702..b8f6ba46 100644 --- a/src/Sandertv/BlockSniper/brush/types/ReplaceType.php +++ b/src/Sandertv/BlockSniper/brush/types/ReplaceType.php @@ -11,15 +11,12 @@ class ReplaceType extends BaseType { - public $player; - public $level; - public $blocks; - public function __construct(Loader $main, Player $player, Level $level, array $blocks) { parent::__construct($main); $this->level = $level; $this->player = $player; $this->blocks = $blocks; + $this->obsolete = Brush::getObsolete($this->player); } /** @@ -28,13 +25,14 @@ public function __construct(Loader $main, Player $player, Level $level, array $b public function fillShape(): bool { $undoBlocks = []; foreach($this->blocks as $block) { - $obsolete = Brush::getObsolete($this->player); $randomBlock = Brush::$brush[$this->player->getId()]["blocks"][array_rand(Brush::$brush[$this->player->getId()]["blocks"])]; - if($block->getId() === $obsolete->getId()) { - if($block->getId() !== $randomBlock->getId()) { - $undoBlocks[] = $block; + foreach($this->obsolete as $obsolete) { + if($block->getId() === $obsolete->getId()) { + if($block->getId() !== $randomBlock->getId()) { + $undoBlocks[] = $block; + } + $this->level->setBlock(new Vector3($block->x, $block->y, $block->z), $randomBlock, false, false); } - $this->level->setBlock(new Vector3($block->x, $block->y, $block->z), $randomBlock, false, false); } } $this->getMain()->getUndoStore()->saveUndo($undoBlocks); @@ -49,10 +47,6 @@ public function getPermission(): string { return "blocksniper.type.replace"; } - 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 cd771718..5769bafa 100644 --- a/src/Sandertv/BlockSniper/cloning/BaseClone.php +++ b/src/Sandertv/BlockSniper/cloning/BaseClone.php @@ -10,6 +10,12 @@ abstract class BaseClone { const TYPE_TEMPLATE = 1; public $owner; + public $level; + protected $name; + + protected $center; + protected $radius; + protected $height; public function __construct(Loader $owner) { $this->owner = $owner; diff --git a/src/Sandertv/BlockSniper/cloning/Copy.php b/src/Sandertv/BlockSniper/cloning/Copy.php index af0e19c0..77929aed 100644 --- a/src/Sandertv/BlockSniper/cloning/Copy.php +++ b/src/Sandertv/BlockSniper/cloning/Copy.php @@ -10,12 +10,6 @@ class Copy extends BaseClone { - public $owner; - public $level; - public $center; - public $radius; - public $height; - public function __construct(Loader $owner, Level $level, Position $center = null, float $radius = null, int $height = 0) { parent::__construct($owner); $this->owner = $owner; diff --git a/src/Sandertv/BlockSniper/cloning/Template.php b/src/Sandertv/BlockSniper/cloning/Template.php index 70c686b1..3da15c9e 100644 --- a/src/Sandertv/BlockSniper/cloning/Template.php +++ b/src/Sandertv/BlockSniper/cloning/Template.php @@ -10,14 +10,6 @@ class Template extends BaseClone { - public $owner; - public $level; - public $name; - - public $center; - public $radius; - public $height; - public function __construct(Loader $owner, Level $level, string $name, Position $center = null, float $radius = null, int $height = 0) { parent::__construct($owner); $this->owner = $owner; diff --git a/src/Sandertv/BlockSniper/commands/BaseCommand.php b/src/Sandertv/BlockSniper/commands/BaseCommand.php index 836a484d..9808850f 100644 --- a/src/Sandertv/BlockSniper/commands/BaseCommand.php +++ b/src/Sandertv/BlockSniper/commands/BaseCommand.php @@ -10,6 +10,8 @@ abstract class BaseCommand extends Command implements PluginIdentifiableCommand { + public $owner; + public function __construct(Loader $owner, $name, $description = "", $usageMessage = null, array $aliases = []) { parent::__construct($name, $description, $usageMessage, $aliases); $this->owner = $owner; diff --git a/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php b/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php index 1b15d387..c685ce04 100644 --- a/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php +++ b/src/Sandertv/BlockSniper/commands/BlockSniperCommand.php @@ -34,11 +34,11 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { } switch(strtolower($args[0])) { - case "language": + /*case "language": $this->getSettings()->set("Message-Language", $args[1]); $this->getSettings()->save(); $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.language")); - return true; + return true;*/ case "reload": $sender->sendMessage(TF::GREEN . "Reloading..."); diff --git a/src/Sandertv/BlockSniper/commands/BrushCommand.php b/src/Sandertv/BlockSniper/commands/BrushCommand.php index c23410ed..e6b1d59c 100644 --- a/src/Sandertv/BlockSniper/commands/BrushCommand.php +++ b/src/Sandertv/BlockSniper/commands/BrushCommand.php @@ -15,7 +15,7 @@ class BrushCommand extends BaseCommand { public function __construct(Loader $owner) { - parent::__construct($owner, "brush", "Change the properties of the brush", " ", ["b", "brushwand"]); + parent::__construct($owner, "brush", "Change the properties of the brush", " ", ["b", "brushwand"]); $this->setPermission("blocksniper.command.brush"); } @@ -30,14 +30,61 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } - if(count($args) !== 2) { - $sender->sendMessage(TF::RED . "[Usage] /brush "); + if(count($args) !== 2 && strtolower($args[0]) !== "reset" && strtolower($args[0]) !== "re" && strtolower($args[1]) !== "delete") { + $sender->sendMessage(TF::RED . "[Usage] /brush "); return true; } Brush::setupDefaultValues($sender); + $action = null; switch(strtolower($args[0])) { + case "preset": + case "pr": + switch($args[1]) { + case "new": + case "create": + if($this->getPlugin()->getPresetManager()->isPreset($args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.preset-already-exists")); + return true; + } + $this->getPlugin()->getPresetManager()->presetCreation[$sender->getId()] = []; + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.preset.name")); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.preset.cancel")); + return true; + + case "list": + $presetList = implode(", ", $this->getPlugin()->getPresetManager()->getAllPresets()); + $sender->sendMessage(TF::GREEN . "--- " . TF::YELLOW . "Preset List" . TF::GREEN . " ---"); + $sender->sendMessage(TF::AQUA . $presetList); + return true; + + case "delete": + if(!$this->getPlugin()->getPresetManager()->isPreset($args[2])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.preset-doesnt-exist")); + return true; + } + $this->getPlugin()->getPresetManager()->deletePreset($args[2]); + $sender->sendMessage(TF::YELLOW . "Preset " . TF::RED . $args[2] . TF::YELLOW . " has been deleted successfully."); + return true; + + default: + if(!$this->getPlugin()->getPresetManager()->isPreset($args[1])) { + $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.preset-doesnt-exist")); + return true; + } + $preset = $this->getPlugin()->getPresetManager()->getPreset($args[1]); + $preset->apply($sender); + $sender->sendMessage(TF::YELLOW . $this->getPlugin()->getTranslation("brush.preset") . TF::BLUE . $preset->name); + foreach($preset->getParsedData() as $key => $value) { + if($value !== null && $key !== "name") { + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush." . $key) . TF::AQUA . $value); + } + } + return true; + } + break; + case "size": case "radius": case "si": @@ -50,7 +97,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } Brush::setSize($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Size: " . TF::AQUA . $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.size") . TF::AQUA . $args[1]); $action = Change::ACTION_CHANGE_SIZE; break; @@ -65,7 +112,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } Brush::setShape($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Shape: " . TF::AQUA . Brush::getShape($sender)->getName()); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.shape") . TF::AQUA . Brush::getShape($sender)->getName()); $action = Change::ACTION_CHANGE_SHAPE; break; @@ -80,7 +127,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } Brush::setType($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Type: " . TF::AQUA . Brush::getType($sender)->getName()); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.type") . TF::AQUA . Brush::getType($sender)->getName()); $action = Change::ACTION_CHANGE_TYPE; break; @@ -91,7 +138,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { return true; } Brush::setHeight($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Height: " . TF::AQUA . $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.height") . TF::AQUA . $args[1]); $action = Change::ACTION_CHANGE_HEIGHT; break; @@ -105,36 +152,42 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { foreach($blocks as $block) { $blockNames[] = $block->getName(); } - $sender->sendMessage(TF::GREEN . "Blocks: " . TF::AQUA . implode(", ", $blockNames)); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.blocks") . TF::AQUA . implode(", ", $blockNames)); $action = Change::ACTION_CHANGE_BLOCKS; break; case "ob": case "obsolete": case "replaced": - Brush::setObsolete($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Obsolete: " . TF::AQUA . Brush::getObsolete($sender)->getName()); + $blocks = explode(",", $args[1]); + Brush::setObsolete($sender, $blocks); + $blocks = Brush::getObsolete($sender); + $blockNames = []; + foreach($blocks as $block) { + $blockNames[] = $block->getName(); + } + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.obsolete") . TF::AQUA . implode(", ", $blockNames)); $action = Change::ACTION_CHANGE_OBSOLETE; break; case "pe": case "perfect": Brush::setPerfect($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Perfect: " . TF::AQUA . $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.perfect") . TF::AQUA . $args[1]); return true; case "gr": // TODO: Fix gravity and move return true to end. case "gravity": return true; Brush::setGravity($sender, $args[1]); - $sender->sendMessage(TF::GREEN . "Gravity: " . TF::AQUA . $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.gravity") . TF::AQUA . $args[1]); case "decrement": case "decrementing": case "de": Brush::setDecrementing($sender, $args[1]); Brush::$resetSize[$sender->getId()] = Brush::getSize($sender); - $sender->sendMessage(TF::GREEN . "Decrement: " . TF::AQUA . $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.decrement") . TF::AQUA . $args[1]); $action = Change::ACTION_CHANGE_DECREMENT; break; @@ -142,12 +195,26 @@ 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::getBiomeId($sender))->getName()); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.biome") . TF::AQUA . Biome::getBiome(Brush::getBiomeId($sender))->getName()); $action = Change::ACTION_CHANGE_BIOME; break; + + case "re": + case "reset": + Brush::resetBrush($sender); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("commands.succeed.brush.reset")); + $action = Change::ACTION_RESET_BRUSH; + break; + + case "ho": + case "hollow": + Brush::setHollow($sender, $args[1]); + $sender->sendMessage(TF::GREEN . $this->getPlugin()->getTranslation("brush.hollow") . TF::AQUA . $args[1]); + $action = Change::ACTION_CHANGE_HOLLOW; + break; default: - $sender->sendMessage(TF::RED . "[Usage] /brush "); + $sender->sendMessage(TF::RED . "[Usage] /brush "); return true; } $this->getPlugin()->getServer()->getPluginManager()->callEvent(new Change($this->getPlugin(), $sender, $action, $args[0])); diff --git a/src/Sandertv/BlockSniper/commands/UndoCommand.php b/src/Sandertv/BlockSniper/commands/UndoCommand.php index 1a6eb63f..eaf01796 100644 --- a/src/Sandertv/BlockSniper/commands/UndoCommand.php +++ b/src/Sandertv/BlockSniper/commands/UndoCommand.php @@ -38,10 +38,12 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { } $undoAmount = 1; - if(is_numeric($args[0])) { - $undoAmount = $args[0]; - if($undoAmount > ($totalUndo = $this->getPlugin()->getUndoStore()->getTotalUndoStores())) { - $undoAmount = $totalUndo; + if(isset($args[0])) { + if(is_numeric($args[0])) { + $undoAmount = $args[0]; + if($undoAmount > ($totalUndo = $this->getPlugin()->getUndoStore()->getTotalUndoStores())) { + $undoAmount = $totalUndo; + } } } diff --git a/src/Sandertv/BlockSniper/commands/cloning/CloneCommand.php b/src/Sandertv/BlockSniper/commands/cloning/CloneCommand.php index 2ddef460..25898056 100644 --- a/src/Sandertv/BlockSniper/commands/cloning/CloneCommand.php +++ b/src/Sandertv/BlockSniper/commands/cloning/CloneCommand.php @@ -42,7 +42,7 @@ public function execute(CommandSender $sender, $commandLabel, array $args) { $sizes = explode("x", strtolower($args[1])); - if((int)$sizes[0] > 70 || (int)$sizes[1] > 70) { + if((int)$sizes[0] > $this->getSettings()->get("Maximum-Clone-Size") || (int)$sizes[1] > $this->getSettings()->get("Maximum-Clone-Size")) { $sender->sendMessage(TF::RED . "[Warning] " . $this->getPlugin()->getTranslation("commands.errors.radius-too-big")); return true; } diff --git a/src/Sandertv/BlockSniper/data/ConfigData.php b/src/Sandertv/BlockSniper/data/ConfigData.php index 433aa5f4..54ab639f 100644 --- a/src/Sandertv/BlockSniper/data/ConfigData.php +++ b/src/Sandertv/BlockSniper/data/ConfigData.php @@ -2,7 +2,6 @@ namespace Sandertv\BlockSniper\data; -use pocketmine\utils\Config; use Sandertv\BlockSniper\Loader; class ConfigData { @@ -15,13 +14,6 @@ public function __construct(Loader $plugin) { $this->collectSettings(); } - /** - * @return Loader - */ - public function getOwner(): Loader { - return $this->plugin; - } - public function collectSettings() { $cfg = yaml_parse_file($this->getOwner()->getDataFolder() . "settings.yml"); $this->settings = [ @@ -29,10 +21,18 @@ public function collectSettings() { "Brush-Item" => $cfg["Brush-Item"], "Maximum-Radius" => $cfg["Maximum-Radius"], "Maximum-Undo-Stores" => $cfg["Maximum-Undo-Stores"], - "Reset-Decrement-Brush" => $cfg["Reset-Decrement-Brush"] + "Reset-Decrement-Brush" => $cfg["Reset-Decrement-Brush"], + "Maximum-Clone-Size" => $cfg["Maximum-Clone-Size"] ]; } + /** + * @return Loader + */ + public function getOwner(): Loader { + return $this->plugin; + } + /** * @param string $key * diff --git a/src/Sandertv/BlockSniper/data/TranslationData.php b/src/Sandertv/BlockSniper/data/TranslationData.php index 4a8c7d2f..46ab5a7d 100644 --- a/src/Sandertv/BlockSniper/data/TranslationData.php +++ b/src/Sandertv/BlockSniper/data/TranslationData.php @@ -15,18 +15,12 @@ public function __construct(Loader $plugin) { $this->collectTranslations(); } - /** - * @return Loader - */ - public function getOwner(): Loader { - return $this->plugin; - } - /** * @return bool */ public function collectTranslations(): bool { $languageSelected = false; + $language = []; foreach($this->getOwner()->availableLanguages as $availableLanguage) { if($this->getOwner()->getSettings()->get("Message-Language") === $availableLanguage) { $this->getOwner()->saveResource("languages/" . $availableLanguage . ".yml"); @@ -37,7 +31,7 @@ public function collectTranslations(): bool { } if(!$languageSelected) { $this->getOwner()->saveResource("languages/en.yml"); - $language = yaml_parse_file($this->getOwner()->getDataFolder() ."languages/en.yml"); + $language = yaml_parse_file($this->getOwner()->getDataFolder() . "languages/en.yml"); } // This is going to burn your eyes. Don't look at it for too long. @@ -54,16 +48,42 @@ public function collectTranslations(): bool { "commands.errors.clone-not-found" => $language["commands"]["errors"]["clone-not-found"], "commands.errors.name-not-set" => $language["commands"]["errors"]["name-not-set"], "commands.errors.template-not-existing" => $language["commands"]["errors"]["template-not-existing"], + "commands.errors.preset-already-exists" => $language["commands"]["errors"]["preset-already-exists"], + "commands.errors.preset-doesnt-exist" => $language["commands"]["errors"]["preset-doesnt-exist"], "commands.succeed.default" => $language["commands"]["succeed"]["default"], "commands.succeed.undo" => $language["commands"]["succeed"]["undo"], "commands.succeed.language" => $language["commands"]["succeed"]["language"], "commands.succeed.paste" => $language["commands"]["succeed"]["paste"], "commands.succeed.clone" => $language["commands"]["succeed"]["clone"], + "commands.succeed.brush.reset" => $language["commands"]["succeed"]["brush"]["reset"], + "commands.succeed.preset.name" => $language["commands"]["succeed"]["preset"]["name"], + "commands.succeed.preset.cancel" => $language["commands"]["succeed"]["preset"]["cancel"], + "commands.succeed.preset.canceled" => $language["commands"]["succeed"]["preset"]["canceled"], + + "brush.shape" => $language["brush"]["shape"], + "brush.type" => $language["brush"]["type"], + "brush.blocks" => $language["brush"]["blocks"], + "brush.size" => $language["brush"]["size"], + "brush.perfect" => $language["brush"]["perfect"], + "brush.obsolete" => $language["brush"]["obsolete"], + "brush.height" => $language["brush"]["height"], + "brush.gravity" => $language["brush"]["gravity"], + "brush.decrement" => $language["brush"]["decrement"], + "brush.biome" => $language["brush"]["biome"], + "brush.hollow" => $language["brush"]["hollow"], + "brush.preset" => $language["brush"]["preset"] ]; return ($languageSelected ? true : false); } + /** + * @return Loader + */ + public function getOwner(): Loader { + return $this->plugin; + } + /** * @param string $key * diff --git a/src/Sandertv/BlockSniper/events/BrushUseEvent.php b/src/Sandertv/BlockSniper/events/BrushUseEvent.php index 94a60b7d..d31fda4a 100644 --- a/src/Sandertv/BlockSniper/events/BrushUseEvent.php +++ b/src/Sandertv/BlockSniper/events/BrushUseEvent.php @@ -2,14 +2,11 @@ namespace Sandertv\BlockSniper\events; -use pocketmine\block\Block; use pocketmine\event\Cancellable; use pocketmine\level\Level; -use pocketmine\math\Vector3; use pocketmine\Player; use Sandertv\BlockSniper\brush\BaseShape; use Sandertv\BlockSniper\brush\BaseType; -use Sandertv\BlockSniper\brush\Brush; use Sandertv\BlockSniper\Loader; class BrushUseEvent extends BaseEvent implements Cancellable { @@ -18,11 +15,15 @@ class BrushUseEvent extends BaseEvent implements Cancellable { public $owner; public $player; + public $type; + public $shape; - public function __construct(Loader $owner, Player $player) { + public function __construct(Loader $owner, Player $player, BaseShape $shape, BaseType $type) { parent::__construct($owner); $this->owner = $owner; $this->player = $player; + $this->type = $type; + $this->shape = $shape; } /** @@ -40,22 +41,13 @@ public function getPlayer(): Player { return $this->player; } - /** - * Returns the size of the player that used the Brush. - * - * @return int - */ - public function getSize(): int { - return Brush::getSize($this->player); - } - /** * Returns the type of the player that used the Brush. (Object) * * @return BaseType */ public function getType(): BaseType { - return Brush::getType($this->player, $this->getShape()->getBlocksInside()); + return $this->type; } /** @@ -64,59 +56,15 @@ public function getType(): BaseType { * @return BaseShape */ public function getShape(): BaseShape { - return Brush::getShape($this->player); - } - - /** - * Returns an array of the blocks that are selected within a shape. - * - * @return array - */ - public function getSelectedBlocks(): array { - return $this->getShape()->getBlocksInside(); - } - - /** - * Returns the center of the shape selected. - * - * @return Vector3 - */ - public function getCenter(): Vector3 { - return $this->getShape()->getCenter(); - } - - /** - * Returns an array of the blocks that will be used to fill the shape. - * - * @return array - */ - public function getBlocks(): array { - return Brush::getBlocks($this->player); + return $this->shape; } /** - * Returns the height of the brush used, being used by cylinders and cuboids. + * Returns the *approximate* amount of blocks in the shape given. * * @return int */ - public function getHeight(): int { - return Brush::getHeight($this->player); - } - - /** - * Returns the obsolete block in case of replace type. - * - * @return Block - */ - public function getObsolete(): Block { - return Brush::getObsolete($this->player); - } - - /** - * Returns true if perfect spheres, false if not. - * @return bool - */ - public function getPerfect(): bool { - return Brush::getPerfect($this->player); + public function getApproximateProcessedBlocks(): int { + return $this->shape->getApproximateProcessedBlocks(); } } diff --git a/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php b/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php index 7e8e6f56..71e562a3 100644 --- a/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php +++ b/src/Sandertv/BlockSniper/events/ChangeBrushPropertiesEvent.php @@ -8,15 +8,17 @@ class ChangeBrushPropertiesEvent extends PluginEvent { - const ACTION_CHANGE_SIZE = 0; - const ACTION_CHANGE_HEIGHT = 1; - const ACTION_CHANGE_TYPE = 2; - const ACTION_CHANGE_SHAPE = 3; - - const ACTION_CHANGE_BLOCKS = 4; - const ACTION_CHANGE_BIOME = 5; - const ACTION_CHANGE_OBSOLETE = 6; - const ACTION_CHANGE_DECREMENT = 7; + const ACTION_RESET_BRUSH = 0; + const ACTION_CHANGE_SIZE = 1; + const ACTION_CHANGE_HEIGHT = 2; + const ACTION_CHANGE_TYPE = 3; + const ACTION_CHANGE_SHAPE = 4; + + const ACTION_CHANGE_BLOCKS = 5; + const ACTION_CHANGE_BIOME = 6; + const ACTION_CHANGE_OBSOLETE = 7; + const ACTION_CHANGE_DECREMENT = 8; + const ACTION_CHANGE_HOLLOW = 9; public static $handlerList = null; diff --git a/src/Sandertv/BlockSniper/listeners/EventListener.php b/src/Sandertv/BlockSniper/listeners/BrushListener.php similarity index 93% rename from src/Sandertv/BlockSniper/listeners/EventListener.php rename to src/Sandertv/BlockSniper/listeners/BrushListener.php index 0bd2b4ef..dfd7a489 100644 --- a/src/Sandertv/BlockSniper/listeners/EventListener.php +++ b/src/Sandertv/BlockSniper/listeners/BrushListener.php @@ -4,13 +4,13 @@ use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; -use pocketmine\utils\TextFormat as TF; use pocketmine\Player; +use pocketmine\utils\TextFormat as TF; use Sandertv\BlockSniper\brush\Brush; use Sandertv\BlockSniper\events\BrushUseEvent; use Sandertv\BlockSniper\Loader; -class EventListener implements Listener { +class BrushListener implements Listener { public $owner; @@ -29,21 +29,20 @@ public function brush(PlayerInteractEvent $event) { return false; } - $this->getOwner()->getServer()->getPluginManager()->callEvent($event = new BrushUseEvent($this->getOwner(), $player)); - if($event->isCancelled()) { - return false; - } - Brush::setupDefaultValues($player); - $shape = Brush::getShape($player); $type = Brush::getType($player, $shape->getBlocksInside()); + $this->getOwner()->getServer()->getPluginManager()->callEvent($event = new BrushUseEvent($this->getOwner(), $player, $shape, $type)); + if($event->isCancelled()) { + return false; + } + $type->fillShape(); $this->decrementBrush($player); - return true; } } + return true; } /** diff --git a/src/Sandertv/BlockSniper/listeners/PresetListener.php b/src/Sandertv/BlockSniper/listeners/PresetListener.php new file mode 100644 index 00000000..f661d7f0 --- /dev/null +++ b/src/Sandertv/BlockSniper/listeners/PresetListener.php @@ -0,0 +1,125 @@ +main = $main; + } + + public function onChat(PlayerChatEvent $event) { + $player = $event->getPlayer(); + if(!$this->getOwner()->getPresetManager()->isCreatingAPreset($player)) { + return false; + } + $message = explode(" ", $event->getMessage()); + + if(strtolower($message[0]) === "cancel") { + $this->getOwner()->getPresetManager()->cancelPresetCreationProcess($player); + $player->sendMessage(TF::YELLOW . $this->getOwner()->getTranslation("commands.succeed.preset.canceled")); + $event->setCancelled(); + return true; + } + + // Ew... I know. + switch($this->getOwner()->getPresetManager()->getCurrentPresetCreationProgress($player)) { + case 0: + $player->sendMessage(TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "name", $message[0]); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.shape")); + break; + case 1: + if(!BaseShape::isShape(strtolower($message[0]))) { + $player->sendMessage(TF::RED . "[Warning] " . $this->getOwner()->getTranslation("commands.errors.shape-not-found")); + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.shape") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "shape", strtolower($message[0])); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.type")); + break; + case 2: + if(!BaseType::isType(strtolower($message[0]))) { + $player->sendMessage(TF::RED . "[Warning] " . $this->getOwner()->getTranslation("commands.errors.shape-not-found")); + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.type") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "type", strtolower($message[0])); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.decrement")); + break; + case 3: + $message[0] = (bool)$message[0]; + if(!is_bool($message[0])) { + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.decrement") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "decrement", $message[0]); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.size")); + break; + case 4: + if(!is_numeric($message[0])) { + return false; + } + if($message[0] > $this->getOwner()->getSettings()->get("Maximum-Radius")) { + $player->sendMessage(TF::RED . "[Warning] " . $this->getOwner()->getTranslation("commands.errors.radius-too-big")); + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.size") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "size", $message[0]); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.hollow")); + break; + case 5: + $message[0] = (bool)$message[0]; + if(!is_bool($message[0])) { + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.hollow") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "hollow", $message[0]); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.height")); + break; + case 6: + if(!is_numeric($message[0])) { + return false; + } + if($message[0] > $this->getOwner()->getSettings()->get("Maximum-Radius")) { + $player->sendMessage(TF::RED . "[Warning] " . $this->getOwner()->getTranslation("commands.errors.radius-too-big")); + return false; + } + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.height") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "height", $message[0]); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.biome")); + break; + case 7: + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.biome") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "biome", strtolower($message[0])); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.obsolete")); + break; + case 8: + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.obsolete") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "obsolete", explode(",", strtolower($message[0]))); + $player->sendMessage(TF::GRAY . $this->getOwner()->getTranslation("brush.blocks")); + break; + case 9: + $player->sendMessage(TF::GREEN . $this->getOwner()->getTranslation("brush.blocks") . TF::AQUA . $message[0]); + $this->getOwner()->getPresetManager()->addToCreationData($player, "blocks", explode(",", strtolower($message[0]))); + $this->getOwner()->getPresetManager()->parsePresetCreationInfo($player, $this->getOwner()->getPresetManager()->getCreationData($player, "name")); + $player->sendMessage(TF::GREEN . "Preset creation process finished successfully."); + break; + } + $event->setCancelled(); + return true; + } + + public function getOwner(): Loader { + return $this->main; + } +} \ No newline at end of file diff --git a/src/Sandertv/BlockSniper/presets/Preset.php b/src/Sandertv/BlockSniper/presets/Preset.php new file mode 100644 index 00000000..90770ba7 --- /dev/null +++ b/src/Sandertv/BlockSniper/presets/Preset.php @@ -0,0 +1,87 @@ +name = $name; + + $this->shape = $shape; + $this->type = $type; + $this->decrement = $decrement; + $this->size = $size; + $this->hollow = $hollow; + + $this->height = $height; + $this->biome = $biome; + $this->obsolete = $obsolete; + $this->blocks = $blocks; + } + + /** + * Applies the preset on a player. + * + * @param Player $player + */ + public function apply(Player $player) { + foreach($this->getParsedData() as $property => $value) { + switch($property) { + case "shape": + Brush::setShape($player, $value); + break; + case "type": + Brush::setType($player, $value); + break; + case "decrement": + Brush::setDecrementing($player, $value); + break; + case "size": + Brush::setSize($player, $value); + break; + case "hollow": + Brush::setHollow($player, $value); + break; + case "height": + Brush::setHeight($player, $value); + break; + case "biome": + Brush::setBiome($player, $value); + break; + case "obsolete": + Brush::setObsolete($player, $value); + break; + case "blocks": + Brush::setBlocks($player, $value); + break; + } + } + } + + /** + * @return array + */ + public function getParsedData(): array { + $data = []; + $data["name"] = $this->name; + $data["shape"] = $this->shape; + $data["type"] = $this->type; + $data["decrement"] = $this->decrement; + $data["size"] = $this->size; + $data["hollow"] = $this->hollow; + $data["blocks"] = $this->blocks; + $data["height"] = $this->height; + $data["biome"] = $this->biome; + $data["obsolete"] = $this->obsolete; + + return $data; + } +} \ No newline at end of file diff --git a/src/Sandertv/BlockSniper/presets/PresetManager.php b/src/Sandertv/BlockSniper/presets/PresetManager.php new file mode 100644 index 00000000..8972473e --- /dev/null +++ b/src/Sandertv/BlockSniper/presets/PresetManager.php @@ -0,0 +1,158 @@ +main = $main; + + if(is_file($main->getDataFolder() . "presets.yml")) { + $this->data = yaml_parse_file($main->getDataFolder() . "presets.yml"); + foreach($this->data as $name => $data) { + $this->addPreset($name); + $main->getLogger()->debug(TF::GREEN . "Preset " . $name . " has been loaded."); + } + unlink($main->getDataFolder() . "presets.yml"); + $main->getLogger()->info(TF::GREEN . "All presets have been loaded."); + } + } + + /** + * @param string $name + */ + public function addPreset(string $name) { + $this->preset[$name] = new Preset( + $this->data[$name]["name"], + $this->data[$name]["shape"], + $this->data[$name]["type"], + $this->data[$name]["decrement"], + $this->data[$name]["size"], + $this->data[$name]["hollow"], + $this->data[$name]["blocks"], + $this->data[$name]["obsolete"], + $this->data[$name]["height"], + $this->data[$name]["biome"]); + unset($this->data[$name]); + } + + /** + * @param string $name + * + * @return bool + */ + public function isPreset(string $name): bool { + return isset($this->preset[$name]); + } + + /** + * @param string $name + * + * @return Preset + */ + public function getPreset(string $name): Preset { + return $this->preset[$name]; + } + + /** + * @param Player $player + * + * @return bool + */ + public function isCreatingAPreset(Player $player): bool { + return isset($this->presetCreation[$player->getId()]); + } + + /** + * @param Player $player + * + * @return int + */ + public function getCurrentPresetCreationProgress(Player $player): int { + return count($this->presetCreation[$player->getId()]); + } + + /** + * @param Player $player + * @param string $name + */ + public function parsePresetCreationInfo(Player $player, string $name) { + foreach($this->presetCreation[$player->getId()] as $key => $value) { + $this->data[$name][$key] = $value; + } + $this->addPreset($name); + unset($this->presetCreation[$player->getId()]); + } + + /** + * @param Player $player + * @param string $key + * @param $value + */ + public function addToCreationData(Player $player, string $key, $value) { + $this->presetCreation[$player->getId()][$key] = $value; + } + + /** + * @param Player $player + * @param string $key + * + * @return mixed + */ + public function getCreationData(Player $player, string $key) { + return $this->presetCreation[$player->getId()][$key]; + } + + /** + * @param Player $player + */ + public function cancelPresetCreationProcess(Player $player) { + unset($this->presetCreation[$player->getId()]); + } + + /** + * @param string $name + */ + public function deletePreset(string $name) { + unset($this->preset[$name]); + } + + public function storePresetsToFile() { + $data = []; + if(isset($this->preset)) { + foreach($this->preset as $name => $preset) { + if($preset instanceof Preset) { + $data[$name] = $preset->getParsedData(); + } + } + } + yaml_emit_file($this->getOwner()->getDataFolder() . "presets.yml", $data); + } + + /** + * @return Loader + */ + public function getOwner(): Loader { + return $this->main; + } + + /** + * @return array + */ + public function getAllPresets(): array { + $presets = []; + foreach($this->preset as $name => $preset) { + $presets[] = $name; + } + return $presets; + } +} \ No newline at end of file