From ded5dadd35e596c3e54010b2ea7a27c3dd8427d1 Mon Sep 17 00:00:00 2001 From: XenialDan Date: Sat, 13 Feb 2021 18:47:02 +0100 Subject: [PATCH] Schematics, Structures and exported Clipboards: unified as "Assets" - Bumped version to 10.1.4, see #221 - plugin_data/structures & plugin_data/schematics folders got merged into plugin_data/assets - Added AssetCommand for handling assets. Still under TODO - Added AssetCollection to cache assets - For now, just dump Asset items to console - vecToString and boolToString moved to API - Added TAG_MAGIC_WE_ASSET to API - UserSession brushes are now saved in a Map - Load schematics and mcstructure in one code block - Code reformat on whole project --- plugin.yml | 3 +- src/xenialdan/MagicWE2/API.php | 11 + src/xenialdan/MagicWE2/EventListener.php | 30 +- src/xenialdan/MagicWE2/Loader.php | 38 +- .../MagicWE2/clipboard/Clipboard.php | 50 +-- .../MagicWE2/clipboard/RevertClipboard.php | 14 +- .../MagicWE2/clipboard/SingleClipboard.php | 42 +-- .../MagicWE2/commands/DonateCommand.php | 28 +- .../MagicWE2/commands/HelpCommand.php | 36 +- .../MagicWE2/commands/InfoCommand.php | 20 +- .../MagicWE2/commands/LanguageCommand.php | 52 +-- .../MagicWE2/commands/LimitCommand.php | 24 +- .../MagicWE2/commands/ReportCommand.php | 20 +- .../MagicWE2/commands/SetRangeCommand.php | 24 +- .../MagicWE2/commands/TestCommand.php | 4 +- .../MagicWE2/commands/VersionCommand.php | 12 +- .../commands/args/LanguageArgument.php | 8 +- .../commands/args/MirrorAxisArgument.php | 2 +- .../commands/args/RotateAngleArgument.php | 4 +- .../commands/biome/BiomeInfoCommand.php | 100 ++--- .../commands/biome/BiomeListCommand.php | 26 +- .../commands/biome/SetBiomeCommand.php | 36 +- .../MagicWE2/commands/brush/BrushCommand.php | 129 +++---- .../clipboard/ClearClipboardCommand.php | 32 +- .../commands/clipboard/CopyCommand.php | 38 +- .../commands/clipboard/Cut2Command.php | 58 +-- .../commands/clipboard/CutCommand.php | 40 +- .../commands/clipboard/FlipCommand.php | 40 +- .../commands/clipboard/PasteCommand.php | 18 +- .../commands/clipboard/RotateCommand.php | 36 +- .../debug/PlaceAllBlockstatesCommand.php | 22 +- .../commands/history/ClearhistoryCommand.php | 32 +- .../MagicWE2/commands/history/RedoCommand.php | 30 +- .../MagicWE2/commands/history/UndoCommand.php | 31 +- .../commands/selection/HPos1Command.php | 74 ++-- .../commands/selection/HPos2Command.php | 74 ++-- .../commands/selection/Pos1Command.php | 64 ++-- .../commands/selection/Pos2Command.php | 64 ++-- .../selection/info/ListChunksCommand.php | 56 +-- .../commands/selection/info/SizeCommand.php | 46 +-- .../MagicWE2/commands/tool/DebugCommand.php | 46 +-- .../MagicWE2/commands/tool/FloodCommand.php | 82 ++-- .../commands/tool/ToggledebugCommand.php | 30 +- .../commands/tool/TogglewandCommand.php | 30 +- .../MagicWE2/commands/tool/WandCommand.php | 46 +-- .../commands/utility/CalculateCommand.php | 18 +- src/xenialdan/MagicWE2/event/MWEEditEvent.php | 86 ++--- .../event/MWESelectionChangeEvent.php | 16 +- .../MagicWE2/helper/AsyncChunkManager.php | 16 +- src/xenialdan/MagicWE2/helper/BlockQuery.php | 2 +- src/xenialdan/MagicWE2/helper/Progress.php | 10 +- src/xenialdan/MagicWE2/helper/Scoreboard.php | 25 +- .../MagicWE2/helper/StructureStore.php | 8 +- .../MagicWE2/selection/shape/Cube.php | 68 ++-- .../MagicWE2/selection/shape/Cuboid.php | 84 ++--- .../MagicWE2/selection/shape/Cylinder.php | 72 ++-- .../MagicWE2/selection/shape/Ellipsoid.php | 114 +++--- .../MagicWE2/selection/shape/Pyramid.php | 82 ++-- .../MagicWE2/selection/shape/Shape.php | 126 +++---- .../selection/shape/ShapeRegistry.php | 94 ++--- .../MagicWE2/session/PluginSession.php | 42 +-- src/xenialdan/MagicWE2/session/Session.php | 352 +++++++++--------- .../MagicWE2/session/UserSession.php | 13 +- src/xenialdan/MagicWE2/session/data/Asset.php | 129 +++++++ .../MagicWE2/session/data/AssetCollection.php | 72 ++++ src/xenialdan/MagicWE2/session/data/TODO.md | 5 + .../MagicWE2/task/AsyncActionTask.php | 54 +-- .../task/AsyncClipboardActionTask.php | 20 +- src/xenialdan/MagicWE2/task/AsyncCopyTask.php | 58 +-- .../MagicWE2/task/AsyncCountTask.php | 20 +- .../MagicWE2/task/AsyncReplaceTask.php | 14 +- .../MagicWE2/task/AsyncRevertTask.php | 38 +- .../MagicWE2/task/action/ActionRegistry.php | 78 ++-- .../MagicWE2/task/action/CountAction.php | 16 +- .../MagicWE2/task/action/CutAction.php | 6 +- .../MagicWE2/task/action/FlipAction.php | 72 ++-- .../MagicWE2/task/action/RotateAction.php | 4 +- .../MagicWE2/task/action/SetBiomeAction.php | 12 +- .../MagicWE2/task/action/SetBlockAction.php | 24 +- .../MagicWE2/task/action/TaskAction.php | 2 +- .../MagicWE2/task/action/ThawAction.php | 18 +- src/xenialdan/MagicWE2/tool/Brush.php | 213 ++++++----- .../MagicWE2/tool/BrushProperties.php | 154 ++++---- src/xenialdan/MagicWE2/tool/WETool.php | 2 +- 84 files changed, 2079 insertions(+), 1862 deletions(-) create mode 100644 src/xenialdan/MagicWE2/session/data/Asset.php create mode 100644 src/xenialdan/MagicWE2/session/data/AssetCollection.php create mode 100644 src/xenialdan/MagicWE2/session/data/TODO.md diff --git a/plugin.yml b/plugin.yml index da583228..77b3e85f 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,9 +1,10 @@ --- name: MagicWE2 main: xenialdan\MagicWE2\Loader -version: 10.1.3 +version: 10.1.4 api: ["4.0.0"] php: [ "7.4", "8.0" ] +softdepend: [ "DEVirion" ] authors: - XenialDan description: Lag free asynchronous world editor for PMMP with plenty of options diff --git a/src/xenialdan/MagicWE2/API.php b/src/xenialdan/MagicWE2/API.php index f8b14a33..5ac3eca8 100644 --- a/src/xenialdan/MagicWE2/API.php +++ b/src/xenialdan/MagicWE2/API.php @@ -70,6 +70,7 @@ class API public const TAG_MAGIC_WE = "MagicWE"; public const TAG_MAGIC_WE_BRUSH = "MagicWEBrush"; + public const TAG_MAGIC_WE_ASSET = "MagicWEAsset"; //TODO Split into separate Class (SchematicStorage?) /** @var Clipboard[] */ @@ -529,4 +530,14 @@ public static function setComponents(Block $block, int $x, int $y, int $z): Bloc [$block->getPos()->x, $block->getPos()->y, $block->getPos()->z] = [$x, $y, $z]; return $block; } + + public static function vecToString(Vector3 $v): string + { + return TF::RESET . "[" . TF::RED . $v->getFloorX() . TF::RESET . ":" . TF::GREEN . $v->getFloorY() . TF::RESET . ":" . TF::BLUE . $v->getFloorZ() . TF::RESET . "]"; + } + + public static function boolToString(bool $b): string + { + return $b ? TF::RESET . TF::GREEN . "On" . TF::RESET : TF::RESET . TF::RED . "Off" . TF::RESET; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/EventListener.php b/src/xenialdan/MagicWE2/EventListener.php index 2e5e9846..513f3a81 100644 --- a/src/xenialdan/MagicWE2/EventListener.php +++ b/src/xenialdan/MagicWE2/EventListener.php @@ -67,8 +67,8 @@ public function onSessionLoad(MWESessionLoadEvent $event): void if (Loader::hasScoreboard()) { try { if (($session = $event->getSession()) instanceof UserSession && $session->isSidebarEnabled()) - /** @var UserSession $session */ - $session->sidebar->handleScoreboard($session); + /** @var UserSession $session */ + $session->sidebar->handleScoreboard($session); } catch (InvalidArgumentException $e) { Loader::getInstance()->getLogger()->logException($e); } @@ -146,6 +146,24 @@ public function onBreak(BlockBreakEvent $event): void } } +// /** +// * @param BlockPlaceEvent $event +// * @throws AssumptionFailedError +// * @throws Error +// */ +// public function onPlace(BlockPlaceEvent $event): void +// { +// if (!is_null($event->getItem()->getNamedTag()->getCompoundTag(API::TAG_MAGIC_WE)) || !is_null($event->getItem()->getNamedTag()->getCompoundTag(API::TAG_MAGIC_WE_BRUSH))) { +// $event->cancel(); +// try { +// $this->onBreakBlock($event); +// } catch (Exception $error) { +// $event->getPlayer()->sendMessage(Loader::PREFIX . TF::RED . "Interaction failed!"); +// $event->getPlayer()->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); +// } +// } +// } + /** * TODO use tool classes * @param BlockBreakEvent $event @@ -195,7 +213,7 @@ private function onBreakBlock(BlockBreakEvent $event): void */ private function onRightClickBlock(PlayerInteractEvent $event): void { - if (!is_null($event->getItem()->getNamedTag()->getCompoundTag(API::TAG_MAGIC_WE))) { + if (!is_null($event->getItem()->getNamedTag()->getCompoundTag(API::TAG_MAGIC_WE)) || !is_null($event->getItem()->getNamedTag()->getCompoundTag(API::TAG_MAGIC_WE_ASSET))) { $event->cancel(); $session = SessionHelper::getUserSession($event->getPlayer()); if (!$session instanceof UserSession) return; @@ -229,6 +247,12 @@ private function onRightClickBlock(PlayerInteractEvent $event): void #} break; } + default: + { + var_dump($event->getItem()); + $event->cancel(); + break; + } } } } diff --git a/src/xenialdan/MagicWE2/Loader.php b/src/xenialdan/MagicWE2/Loader.php index 608e22b1..079f052b 100644 --- a/src/xenialdan/MagicWE2/Loader.php +++ b/src/xenialdan/MagicWE2/Loader.php @@ -23,6 +23,7 @@ use RuntimeException; use xenialdan\apibossbar\DiverseBossBar; use xenialdan\customui\API as CustomUIAPI; +use xenialdan\MagicWE2\commands\asset\AssetCommand; use xenialdan\MagicWE2\commands\biome\BiomeInfoCommand; use xenialdan\MagicWE2\commands\biome\BiomeListCommand; use xenialdan\MagicWE2\commands\biome\SetBiomeCommand; @@ -71,6 +72,7 @@ use xenialdan\MagicWE2\helper\BlockStatesParser; use xenialdan\MagicWE2\helper\SessionHelper; use xenialdan\MagicWE2\selection\shape\ShapeRegistry; +use xenialdan\MagicWE2\session\data\AssetCollection; use xenialdan\MagicWE2\session\UserSession; use xenialdan\MagicWE2\task\action\ActionRegistry; @@ -100,6 +102,8 @@ class Loader extends PluginBase public $wailaBossBar; /** @var null|string */ public static $scoreboardAPI; + /** @var AssetCollection */ + public static AssetCollection $assetCollection; /** * Returns an instance of the plugin @@ -173,8 +177,9 @@ public function onLoad(): void } $blockstateparserInstance->setAliasMap(json_decode($fileGetContents, true, 512, JSON_THROW_ON_ERROR)); - #StructureStore::getInstance(); - $blockstateparserInstance::runTests();//TODO REMOVE, DEBUG!!!!!!! + //$blockstateparserInstance::runTests();//TODO REMOVE, DEBUG!!!!!!! + + self::$assetCollection = new AssetCollection(); } /** @@ -211,6 +216,8 @@ public function onEnable(): void new HPos1Command($this, "/hpos1", "Set position 1 to targeted block", ["/h1"]), new HPos2Command($this, "/hpos2", "Set position 2 to targeted block", ["/h2"]), new ChunkCommand($this, "/chunk", "Set the selection to your current chunk"), + /* -- assets -- */ + new AssetCommand($this, "/asset", "Manage assets (schematics, structures, clipboard)"), /* -- tool -- */ new WandCommand($this, "/wand", "Gives you the selection wand"), new TogglewandCommand($this, "/togglewand", "Toggle the wand tool on/off", ["/toggleeditwand"]), @@ -315,33 +322,6 @@ public function onEnable(): void } else { $this->getLogger()->notice(TF::RED . "Scoreboard API NOT found, can NOT use scoreboards"); } -// .mcstructure loading tests -// $world = self::getInstance()->getServer()->getWorldManager()->getDefaultWorld(); -// if ($world !== null) { -// $spawn = $world->getSafeSpawn()->asVector3(); -// $structureFiles = glob($this->getDataFolder() . 'structures' . DIRECTORY_SEPARATOR . "*.mcstructure"); -// if ($structureFiles !== false) -// foreach ($structureFiles as $file) { -// $this->getLogger()->debug(TF::GOLD . "Loading " . basename($file)); -// try { -// /** @var StructureStore $instance */ -// $instance = StructureStore::getInstance(); -// $structure = $instance->loadStructure(basename($file)); -// //this will dump wrong blocks for now -// foreach ($structure->blocks() as $block) { -// #$this->getLogger()->debug($block->getPos()->asVector3() . ' ' . BlockStatesParser::printStates(BlockStatesParser::getStateByBlock($block), false)); -// $world->setBlock(($at = $spawn->addVector($block->getPos()->asVector3())), $block); -// if (($tile = $structure->translateBlockEntity(Position::fromObject($block->getPos()->asVector3(), $world), $at)) instanceof Tile) { -// $tileAt = $world->getTileAt($block->getPos()->getFloorX(), $block->getPos()->getFloorY(), $block->getPos()->getFloorZ()); -// if ($tileAt !== null) $world->removeTile($tileAt); -// $world->addTile($tile); -// } -// } -// } catch (Exception $e) { -// $this->getLogger()->debug($e->getMessage()); -// } -// } -// } //register WAILA bar $this->wailaBossBar = new DiverseBossBar(); diff --git a/src/xenialdan/MagicWE2/clipboard/Clipboard.php b/src/xenialdan/MagicWE2/clipboard/Clipboard.php index 997776ed..455c2f93 100644 --- a/src/xenialdan/MagicWE2/clipboard/Clipboard.php +++ b/src/xenialdan/MagicWE2/clipboard/Clipboard.php @@ -46,11 +46,11 @@ public static function getChunkManager(array $chunks): AsyncChunkManager return $manager; } - /** - * @return World - * @throws Exception - */ - public function getWorld(): World + /** + * @return World + * @throws Exception + */ + public function getWorld(): World { if (is_null($this->worldId)) { throw new SelectionException("World is not set!"); @@ -70,27 +70,27 @@ public function setWorld(World $world): void $this->worldId = $world->getId(); } - /** - * @return int - */ - public function getWorldId(): int - { + /** + * @return int + */ + public function getWorldId(): int + { return $this->worldId; - } + } - /** - * @return string - */ - public function getCustomName(): string - { - return $this->customName; - } + /** + * @return string + */ + public function getCustomName(): string + { + return $this->customName; + } - /** - * @param string $customName - */ - public function setCustomName(string $customName): void - { - $this->customName = $customName; - } + /** + * @param string $customName + */ + public function setCustomName(string $customName): void + { + $this->customName = $customName; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/clipboard/RevertClipboard.php b/src/xenialdan/MagicWE2/clipboard/RevertClipboard.php index 558bfa92..28543856 100644 --- a/src/xenialdan/MagicWE2/clipboard/RevertClipboard.php +++ b/src/xenialdan/MagicWE2/clipboard/RevertClipboard.php @@ -38,10 +38,10 @@ public function __construct(int $worldId, array $chunks = [], array $blocksAfter * String representation of object * @link http://php.net/manual/en/serializable.serialize.php * @return string the string representation of the object or null - * @since 5.1.0 - */ - public function serialize() - { + * @since 5.1.0 + */ + public function serialize() + { $chunks = []; foreach ($this->chunks as $hash => $chunk) { $chunks[$hash] = FastChunkSerializer::serialize($chunk); @@ -53,7 +53,7 @@ public function serialize() ]); } - /** + /** * Constructs the object * @link http://php.net/manual/en/serializable.unserialize.php * @param string $serialized

@@ -63,8 +63,8 @@ public function serialize() * @since 5.1.0 * @noinspection PhpMissingParamTypeInspection */ - public function unserialize($serialized) - { + public function unserialize($serialized) + { [ $this->worldId, $chunks, diff --git a/src/xenialdan/MagicWE2/clipboard/SingleClipboard.php b/src/xenialdan/MagicWE2/clipboard/SingleClipboard.php index 5715a006..5ef5c624 100644 --- a/src/xenialdan/MagicWE2/clipboard/SingleClipboard.php +++ b/src/xenialdan/MagicWE2/clipboard/SingleClipboard.php @@ -55,23 +55,23 @@ public function iterateEntries(?int &$x, ?int &$y, ?int &$z): Generator public function getTotalCount(): int { return count($this->entries); - } + } - /** - * String representation of object - * @link https://php.net/manual/en/serializable.serialize.php - * @return string the string representation of the object or null - * @since 5.1 - */ - public function serialize() - { - // TODO: Implement serialize() method. - return serialize([ - $this->entries, - $this->selection, - $this->position - ]); - } + /** + * String representation of object + * @link https://php.net/manual/en/serializable.serialize.php + * @return string the string representation of the object or null + * @since 5.1 + */ + public function serialize() + { + // TODO: Implement serialize() method. + return serialize([ + $this->entries, + $this->selection, + $this->position + ]); + } /** * Constructs the object @@ -83,13 +83,13 @@ public function serialize() * @since 5.1 * @noinspection PhpMissingParamTypeInspection */ - public function unserialize($serialized) - { - // TODO: Implement unserialize() method. - [ + public function unserialize($serialized) + { + // TODO: Implement unserialize() method. + [ $this->entries, $this->selection, $this->position ] = unserialize($serialized/*, ['allowed_classes' => [BlockEntry::class, Selection::class, Vector3::class]]*/); - } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/commands/DonateCommand.php b/src/xenialdan/MagicWE2/commands/DonateCommand.php index 7ed4ce88..25187922 100644 --- a/src/xenialdan/MagicWE2/commands/DonateCommand.php +++ b/src/xenialdan/MagicWE2/commands/DonateCommand.php @@ -31,20 +31,20 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { - $name = TF::DARK_PURPLE . "[" . TF::GOLD . "XenialDan" . TF::DARK_PURPLE . "] "; - $sender->sendMessage($name . "Greetings! Would you like to buy me an energy drink to stay awake during coding sessions?"); - $sender->sendMessage($name . "Donations are welcomed! Consider donating on " . TF::DARK_AQUA . "Pay" . TF::AQUA . "Pal:"); - $sender->sendMessage($name . TF::DARK_AQUA . "https://www.paypal.me/xenialdan"); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { + $name = TF::DARK_PURPLE . "[" . TF::GOLD . "XenialDan" . TF::DARK_PURPLE . "] "; + $sender->sendMessage($name . "Greetings! Would you like to buy me an energy drink to stay awake during coding sessions?"); + $sender->sendMessage($name . "Donations are welcomed! Consider donating on " . TF::DARK_AQUA . "Pay" . TF::AQUA . "Pal:"); + $sender->sendMessage($name . TF::DARK_AQUA . "https://www.paypal.me/xenialdan"); $sender->sendMessage($name . "Thank you! With " . TF::BOLD . TF::RED . "<3" . TF::RESET . TF::DARK_PURPLE . " - MagicWE2 by https://github.com/thebigsmileXD"); $colorHeart = (random_int(0, 1) === 1 ? TF::DARK_RED : TF::DARK_PURPLE); $sender->sendMessage( diff --git a/src/xenialdan/MagicWE2/commands/HelpCommand.php b/src/xenialdan/MagicWE2/commands/HelpCommand.php index e3025f90..84ccc5e1 100644 --- a/src/xenialdan/MagicWE2/commands/HelpCommand.php +++ b/src/xenialdan/MagicWE2/commands/HelpCommand.php @@ -35,18 +35,18 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { - $cmds = []; - if (empty($args["command"])) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { + $cmds = []; + if (empty($args["command"])) { foreach (array_filter(Loader::getInstance()->getServer()->getCommandMap()->getCommands(), static function (Command $command) use ($sender) { return strpos($command->getName(), "/") !== false && $command->testPermissionSilent($sender); }) as $cmd) { @@ -60,12 +60,12 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $sender->sendMessage(TF::RED . str_replace("/", "//", $lang->translateString("%commands.generic.notFound"))); return; } - foreach ($cmds as $command) { - $message = TF::LIGHT_PURPLE . "/" . $command->getName(); - if (!empty(($aliases = $command->getAliases()))) { - foreach ($aliases as $i => $alias) { - $aliases[$i] = "/" . $alias; - } + foreach ($cmds as $command) { + $message = TF::LIGHT_PURPLE . "/" . $command->getName(); + if (!empty(($aliases = $command->getAliases()))) { + foreach ($aliases as $i => $alias) { + $aliases[$i] = "/" . $alias; + } $message .= TF::DARK_PURPLE . " [" . implode(",", $aliases) . "]"; } $message .= TF::AQUA . " " . $command->getDescription() . TF::EOL . " - " . $command->getUsage(); diff --git a/src/xenialdan/MagicWE2/commands/InfoCommand.php b/src/xenialdan/MagicWE2/commands/InfoCommand.php index 905a0419..074a598d 100644 --- a/src/xenialdan/MagicWE2/commands/InfoCommand.php +++ b/src/xenialdan/MagicWE2/commands/InfoCommand.php @@ -31,16 +31,16 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { $sender->sendMessage(rtrim(Loader::PREFIX, " ") . " " . $lang->translateString('command.info.title')); foreach (Loader::getInfo() as $i => $line) { if ($i <= 1) continue; diff --git a/src/xenialdan/MagicWE2/commands/LanguageCommand.php b/src/xenialdan/MagicWE2/commands/LanguageCommand.php index 4f5a40a2..dadf3305 100644 --- a/src/xenialdan/MagicWE2/commands/LanguageCommand.php +++ b/src/xenialdan/MagicWE2/commands/LanguageCommand.php @@ -38,36 +38,36 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - if (isset($args["language"])) { + } + if (isset($args["language"])) { $session->setLanguage((string)$args["language"]); return; } - $languages = Loader::getInstance()->getLanguageList(); - $form = new CustomForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.language.title')); - $form->addElement(new Label($lang->translateString('ui.language.label'))); - $dropdown = new Dropdown($lang->translateString('ui.language.dropdown'), array_values($languages)); - $dropdown->setOptionAsDefault($session->getLanguage()->getName()); - $form->addElement($dropdown); - $form->setCallable(function (Player $player, $data) use ($session, $languages) { + $languages = Loader::getInstance()->getLanguageList(); + $form = new CustomForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.language.title')); + $form->addElement(new Label($lang->translateString('ui.language.label'))); + $dropdown = new Dropdown($lang->translateString('ui.language.dropdown'), array_values($languages)); + $dropdown->setOptionAsDefault($session->getLanguage()->getName()); + $form->addElement($dropdown); + $form->setCallable(function (Player $player, $data) use ($session, $languages) { $langShort = array_search($data[1], $languages, true); if (!is_string($langShort)) throw new InvalidArgumentException("Invalid data received"); $session->setLanguage($langShort); diff --git a/src/xenialdan/MagicWE2/commands/LimitCommand.php b/src/xenialdan/MagicWE2/commands/LimitCommand.php index 80320b37..0fd34061 100644 --- a/src/xenialdan/MagicWE2/commands/LimitCommand.php +++ b/src/xenialdan/MagicWE2/commands/LimitCommand.php @@ -36,18 +36,18 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { - if (empty($args["limit"])) { - $limit = Loader::getInstance()->getConfig()->get("limit", -1); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { + if (empty($args["limit"])) { + $limit = Loader::getInstance()->getConfig()->get("limit", -1); $sender->sendMessage(Loader::PREFIX . TF::GREEN . $lang->translateString('command.limit.current', [($limit < 0 ? ucfirst(Loader::getInstance()->getLanguage()->translateString('disabled')) : $limit)])); } else { Loader::getInstance()->getConfig()->set("limit", (int)$args["limit"]); diff --git a/src/xenialdan/MagicWE2/commands/ReportCommand.php b/src/xenialdan/MagicWE2/commands/ReportCommand.php index 4712eb1d..1691b8b7 100644 --- a/src/xenialdan/MagicWE2/commands/ReportCommand.php +++ b/src/xenialdan/MagicWE2/commands/ReportCommand.php @@ -36,16 +36,16 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { $url = "Please report your bug with this link (link also in console)" . TF::EOL; $url .= "https://github.com/thebigsmileXD/MagicWE2/issues/new?labels=Bug&body="; $url .= urlencode( diff --git a/src/xenialdan/MagicWE2/commands/SetRangeCommand.php b/src/xenialdan/MagicWE2/commands/SetRangeCommand.php index cf7556c3..60e1171d 100644 --- a/src/xenialdan/MagicWE2/commands/SetRangeCommand.php +++ b/src/xenialdan/MagicWE2/commands/SetRangeCommand.php @@ -36,18 +36,18 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - try { - if (empty($args["range"])) { - $range = Loader::getInstance()->getToolDistance(); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + try { + if (empty($args["range"])) { + $range = Loader::getInstance()->getToolDistance(); $sender->sendMessage(Loader::PREFIX . TF::GREEN . $lang->translateString('command.setrange.current', [$range])); } else { Loader::getInstance()->getConfig()->set("tool-range", (int)$args["range"]); diff --git a/src/xenialdan/MagicWE2/commands/TestCommand.php b/src/xenialdan/MagicWE2/commands/TestCommand.php index 8c76455b..f16dc71a 100644 --- a/src/xenialdan/MagicWE2/commands/TestCommand.php +++ b/src/xenialdan/MagicWE2/commands/TestCommand.php @@ -46,8 +46,8 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo } } try { - //TODO REMOVE DEBUG - $pluginSession = SessionHelper::createPluginSession(Loader::getInstance()); + //TODO REMOVE DEBUG + $pluginSession = SessionHelper::createPluginSession(Loader::getInstance()); $selection = new Selection($pluginSession->getUUID(), Server::getInstance()->getWorldManager()->getDefaultWorld(), 0, 0, 0, 0, 0, 0); $pluginSession->addSelection($selection); Server::getInstance()->getAsyncPool()->submitTask( diff --git a/src/xenialdan/MagicWE2/commands/VersionCommand.php b/src/xenialdan/MagicWE2/commands/VersionCommand.php index 290d38e6..b8166e60 100644 --- a/src/xenialdan/MagicWE2/commands/VersionCommand.php +++ b/src/xenialdan/MagicWE2/commands/VersionCommand.php @@ -31,12 +31,12 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); } catch (SessionException $e) { } } diff --git a/src/xenialdan/MagicWE2/commands/args/LanguageArgument.php b/src/xenialdan/MagicWE2/commands/args/LanguageArgument.php index 942f98dd..e4d86fc0 100644 --- a/src/xenialdan/MagicWE2/commands/args/LanguageArgument.php +++ b/src/xenialdan/MagicWE2/commands/args/LanguageArgument.php @@ -32,8 +32,8 @@ public function getEnumValues(): array return array_values(Loader::getInstance()->getLanguageList()); } - public function getEnumName(): string - { - return "language"; - } + public function getEnumName(): string + { + return "language"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/commands/args/MirrorAxisArgument.php b/src/xenialdan/MagicWE2/commands/args/MirrorAxisArgument.php index 5090e1b5..fd2fb847 100644 --- a/src/xenialdan/MagicWE2/commands/args/MirrorAxisArgument.php +++ b/src/xenialdan/MagicWE2/commands/args/MirrorAxisArgument.php @@ -9,7 +9,7 @@ class MirrorAxisArgument extends StringEnumArgument { - protected const VALUES = ["x" => "x", "z" => "z", "y" => "y", "xz" => "xz"]; + protected const VALUES = ["x" => "x", "z" => "z", "y" => "y", "xz" => "xz"]; public function getTypeName(): string { diff --git a/src/xenialdan/MagicWE2/commands/args/RotateAngleArgument.php b/src/xenialdan/MagicWE2/commands/args/RotateAngleArgument.php index 9b2000c1..5503e86d 100644 --- a/src/xenialdan/MagicWE2/commands/args/RotateAngleArgument.php +++ b/src/xenialdan/MagicWE2/commands/args/RotateAngleArgument.php @@ -9,8 +9,8 @@ class RotateAngleArgument extends StringEnumArgument { - /** @var array */ - protected const VALUES = ["90" => 90, "180" => 180, "270" => 270]; + /** @var array */ + protected const VALUES = ["90" => 90, "180" => 180, "270" => 270]; public function getTypeName(): string { diff --git a/src/xenialdan/MagicWE2/commands/biome/BiomeInfoCommand.php b/src/xenialdan/MagicWE2/commands/biome/BiomeInfoCommand.php index dac556ce..99e09a86 100644 --- a/src/xenialdan/MagicWE2/commands/biome/BiomeInfoCommand.php +++ b/src/xenialdan/MagicWE2/commands/biome/BiomeInfoCommand.php @@ -43,28 +43,28 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $biomeNames = (new ReflectionClass(Biome::class))->getConstants(); - $biomeNames = array_flip($biomeNames); - unset($biomeNames[Biome::MAX_BIOMES]); + } + $biomeNames = (new ReflectionClass(Biome::class))->getConstants(); + $biomeNames = array_flip($biomeNames); + unset($biomeNames[Biome::MAX_BIOMES]); array_walk($biomeNames, static function (&$value, $key) { $value = BiomeRegistry::getInstance()->getBiome($key)->getName(); }); @@ -85,37 +85,37 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.biomeinfo.atposition')); $session->sendMessage(TF::AQUA . "ID: $biomeId Name: " . $biomeNames[$biomeId]); } - return; - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { + return; + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); - } - if (!$selection->isValid()) { + } + if (!$selection->isValid()) { throw new SelectionException($lang->translateString('error.selectioninvalid')); - } - if ($selection->getWorld() !== $sender->getWorld()) { + } + if ($selection->getWorld() !== $sender->getWorld()) { $sender->sendMessage(Loader::PREFIX . TF::GOLD . $lang->translateString('warning.differentworld')); - } - $touchedChunks = $selection->getShape()->getTouchedChunks($selection->getWorld()); - $biomes = []; - foreach ($touchedChunks as $touchedChunk) { - for ($x = 0; $x < 16; $x++) - for ($z = 0; $z < 16; $z++) + } + $touchedChunks = $selection->getShape()->getTouchedChunks($selection->getWorld()); + $biomes = []; + foreach ($touchedChunks as $touchedChunk) { + for ($x = 0; $x < 16; $x++) + for ($z = 0; $z < 16; $z++) $biomes[] = (FastChunkSerializer::deserialize($touchedChunk)->getBiomeId($x, $z)); - } - $biomes = array_unique($biomes); - $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.biomeinfo.result', [count($biomes)])); - foreach ($biomes as $biomeId) { - $session->sendMessage(TF::AQUA . $lang->translateString('command.biomeinfo.result.line', [$biomeId, $biomeNames[$biomeId]])); - } - } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + } + $biomes = array_unique($biomes); + $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.biomeinfo.result', [count($biomes)])); + foreach ($biomes as $biomeId) { + $session->sendMessage(TF::AQUA . $lang->translateString('command.biomeinfo.result.line', [$biomeId, $biomeNames[$biomeId]])); + } + } catch (Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/biome/BiomeListCommand.php b/src/xenialdan/MagicWE2/commands/biome/BiomeListCommand.php index bc5bdcb8..41ad97ce 100644 --- a/src/xenialdan/MagicWE2/commands/biome/BiomeListCommand.php +++ b/src/xenialdan/MagicWE2/commands/biome/BiomeListCommand.php @@ -34,19 +34,19 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - /** @var Player $sender */ - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + /** @var Player $sender */ + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.biomelist.title')); - foreach ((new ReflectionClass(Biome::class))->getConstants() as $name => $value) { + } + $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.biomelist.title')); + foreach ((new ReflectionClass(Biome::class))->getConstants() as $name => $value) { if ($value === Biome::MAX_BIOMES) continue; $name = BiomeRegistry::getInstance()->getBiome($value)->getName(); $session->sendMessage(TF::AQUA . $lang->translateString('command.biomelist.result.line', [$value, $name])); @@ -58,5 +58,5 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $sender->sendMessage($this->getUsage()); } } - } + } } diff --git a/src/xenialdan/MagicWE2/commands/biome/SetBiomeCommand.php b/src/xenialdan/MagicWE2/commands/biome/SetBiomeCommand.php index c6e2b224..d7d0219f 100644 --- a/src/xenialdan/MagicWE2/commands/biome/SetBiomeCommand.php +++ b/src/xenialdan/MagicWE2/commands/biome/SetBiomeCommand.php @@ -39,25 +39,25 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } + } $selection = $session->getLatestSelection(); if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); diff --git a/src/xenialdan/MagicWE2/commands/brush/BrushCommand.php b/src/xenialdan/MagicWE2/commands/brush/BrushCommand.php index 013e9d9b..b9990695 100644 --- a/src/xenialdan/MagicWE2/commands/brush/BrushCommand.php +++ b/src/xenialdan/MagicWE2/commands/brush/BrushCommand.php @@ -25,75 +25,76 @@ class BrushCommand extends BaseCommand { - /** - * This is where all the arguments, permissions, sub-commands, etc would be registered - * @throws InvalidArgumentException - */ - protected function prepare(): void - { - $this->registerSubCommand(new BrushNameCommand("name", "Get name or rename a brush")); + /** + * This is where all the arguments, permissions, sub-commands, etc would be registered + * @throws InvalidArgumentException + */ + protected function prepare(): void + { + $this->registerSubCommand(new BrushNameCommand("name", "Get name or rename a brush")); $this->setPermission("we.command.brush"); - } + } - /** + /** * @param CommandSender $sender * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (!$session instanceof UserSession) { - throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $form = new SimpleForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.brush.title'), $lang->translateString('ui.brush.content')); - $form->addButton(new Button($lang->translateString('ui.brush.create'))); - $form->addButton(new Button($lang->translateString('ui.brush.getsession'))); - $form->addButton(new Button($lang->translateString('ui.brush.edithand'))); - $form->setCallable(function (Player $player, $data) use ($lang, $session) { - try { - switch ($data) { - case $lang->translateString('ui.brush.create'): - { - $brush = new Brush(new BrushProperties()); - if ($brush instanceof Brush) { - $player->sendForm($brush->getForm()); - } - break; - } - case $lang->translateString('ui.brush.getsession'): - { - $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST); - foreach ($session->getBrushes() as $brush) { - $menu->getInventory()->addItem($brush->toItem()); - } - $menu->send($player, "Session brushes"); - break; - } - case $lang->translateString('ui.brush.edithand'): - { - $brush = $session->getBrushFromItem($player->getInventory()->getItemInHand()); - if ($brush instanceof Brush) { - $player->sendForm($brush->getForm(false)); - } - break; - } - } - return null; - } catch (Exception $error) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (!$session instanceof UserSession) { + throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); + } + $form = new SimpleForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.brush.title'), $lang->translateString('ui.brush.content')); + $form->addButton(new Button($lang->translateString('ui.brush.create'))); + $form->addButton(new Button($lang->translateString('ui.brush.getsession'))); + $form->addButton(new Button($lang->translateString('ui.brush.edithand'))); + $form->setCallable(function (Player $player, $data) use ($lang, $session) { + try { + switch ($data) { + case $lang->translateString('ui.brush.create'): + { + $brush = new Brush(new BrushProperties()); + if ($brush instanceof Brush) { + $player->sendForm($brush->getForm()); + } + break; + } + case $lang->translateString('ui.brush.getsession'): + { + $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST); + foreach ($session->getBrushes() as $brush) { + var_dump($brush); + $menu->getInventory()->addItem($brush->toItem()); + } + $menu->send($player, "Session brushes"); + break; + } + case $lang->translateString('ui.brush.edithand'): + { + $brush = $session->getBrushFromItem($player->getInventory()->getItemInHand()); + if ($brush instanceof Brush) { + $player->sendForm($brush->getForm(false)); + } + break; + } + } + return null; + } catch (Exception $error) { $session->sendMessage(TF::RED . $lang->translateString('error')); $session->sendMessage(TF::RED . $error->getMessage()); } @@ -123,5 +124,5 @@ public static function generateLore(array $elements, array $data): array $return[] = ($element->getText() . ": " . $data[$i]); } return $return; - } + } } diff --git a/src/xenialdan/MagicWE2/commands/clipboard/ClearClipboardCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/ClearClipboardCommand.php index 45c65689..cc782867 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/ClearClipboardCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/ClearClipboardCommand.php @@ -32,22 +32,22 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); } diff --git a/src/xenialdan/MagicWE2/commands/clipboard/CopyCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/CopyCommand.php index 77b6b53a..b006a33a 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/CopyCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/CopyCommand.php @@ -37,26 +37,26 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); + } + $selection = $session->getLatestSelection(); if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); } diff --git a/src/xenialdan/MagicWE2/commands/clipboard/Cut2Command.php b/src/xenialdan/MagicWE2/commands/clipboard/Cut2Command.php index 876f721d..7dc16cec 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/Cut2Command.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/Cut2Command.php @@ -41,41 +41,41 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); - } - if (!$selection->isValid()) { + } + if (!$selection->isValid()) { throw new SelectionException($lang->translateString('error.selectioninvalid')); - } - if ($selection->getWorld() !== $sender->getWorld()) { + } + if ($selection->getWorld() !== $sender->getWorld()) { $sender->sendMessage(Loader::PREFIX . TF::GOLD . $lang->translateString('warning.differentworld')); - } - #$hasFlags = isset($args["flags"]); - $action = new CutAction(); + } + #$hasFlags = isset($args["flags"]); + $action = new CutAction(); $offset = $selection->getShape()->getMinVec3()->subtractVector($session->getPlayer()->getPosition()->asVector3()->floor())->floor(); $action->setClipboardVector($offset); - Server::getInstance()->getAsyncPool()->submitTask( - new AsyncActionTask( + Server::getInstance()->getAsyncPool()->submitTask( + new AsyncActionTask( $session->getUUID(), $selection, $action, diff --git a/src/xenialdan/MagicWE2/commands/clipboard/CutCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/CutCommand.php index 769daffe..16a56bc0 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/CutCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/CutCommand.php @@ -38,27 +38,27 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); } if (!$selection->isValid()) { diff --git a/src/xenialdan/MagicWE2/commands/clipboard/FlipCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/FlipCommand.php index 9f4cc7ef..40fdc672 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/FlipCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/FlipCommand.php @@ -40,21 +40,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $axis = (string)$args["axis"];//TODO change to Axis[] $sender->sendMessage(Loader::PREFIX . $lang->translateString('command.flip.try', [$axis])); $session = SessionHelper::getUserSession($sender); @@ -66,11 +66,11 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo throw new SessionException($lang->translateString('error.noclipboard')); } $action = new FlipAction($axis); - #$offset = $selection->getShape()->getMinVec3()->subtract($session->getPlayer()->asVector3()->floor())->floor(); - #$action->setClipboardVector($offset); - Server::getInstance()->getAsyncPool()->submitTask( - new AsyncClipboardActionTask( - $session->getUUID(), + #$offset = $selection->getShape()->getMinVec3()->subtract($session->getPlayer()->asVector3()->floor())->floor(); + #$action->setClipboardVector($offset); + Server::getInstance()->getAsyncPool()->submitTask( + new AsyncClipboardActionTask( + $session->getUUID(), $clipboard->selection, $action, $clipboard diff --git a/src/xenialdan/MagicWE2/commands/clipboard/PasteCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/PasteCommand.php index 55b1ec66..e3660ddd 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/PasteCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/PasteCommand.php @@ -50,16 +50,16 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo } } if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $clipboard = $session->getCurrentClipboard(); + } + $clipboard = $session->getCurrentClipboard(); if (is_null($clipboard)) { throw new SelectionException($lang->translateString('error.noclipboard')); } diff --git a/src/xenialdan/MagicWE2/commands/clipboard/RotateCommand.php b/src/xenialdan/MagicWE2/commands/clipboard/RotateCommand.php index 961e8a3d..bb624bcf 100644 --- a/src/xenialdan/MagicWE2/commands/clipboard/RotateCommand.php +++ b/src/xenialdan/MagicWE2/commands/clipboard/RotateCommand.php @@ -41,25 +41,25 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $angle = (int)$args["angle"]; + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $angle = (int)$args["angle"]; $aroundOrigin = $args["aroundOrigin"] ?? true; - $sender->sendMessage(Loader::PREFIX . $lang->translateString('command.rotate.try', [$angle])); - $session = SessionHelper::getUserSession($sender); + $sender->sendMessage(Loader::PREFIX . $lang->translateString('command.rotate.try', [$angle])); + $session = SessionHelper::getUserSession($sender); if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); } diff --git a/src/xenialdan/MagicWE2/commands/debug/PlaceAllBlockstatesCommand.php b/src/xenialdan/MagicWE2/commands/debug/PlaceAllBlockstatesCommand.php index c4ca5474..a213c2a9 100644 --- a/src/xenialdan/MagicWE2/commands/debug/PlaceAllBlockstatesCommand.php +++ b/src/xenialdan/MagicWE2/commands/debug/PlaceAllBlockstatesCommand.php @@ -31,17 +31,17 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); return; } /** @var Player $sender */ diff --git a/src/xenialdan/MagicWE2/commands/history/ClearhistoryCommand.php b/src/xenialdan/MagicWE2/commands/history/ClearhistoryCommand.php index 42e1eb13..6fd92d1e 100644 --- a/src/xenialdan/MagicWE2/commands/history/ClearhistoryCommand.php +++ b/src/xenialdan/MagicWE2/commands/history/ClearhistoryCommand.php @@ -32,22 +32,22 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); } diff --git a/src/xenialdan/MagicWE2/commands/history/RedoCommand.php b/src/xenialdan/MagicWE2/commands/history/RedoCommand.php index c2f197d6..937e5efd 100644 --- a/src/xenialdan/MagicWE2/commands/history/RedoCommand.php +++ b/src/xenialdan/MagicWE2/commands/history/RedoCommand.php @@ -32,21 +32,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $session = SessionHelper::getUserSession($sender); if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); diff --git a/src/xenialdan/MagicWE2/commands/history/UndoCommand.php b/src/xenialdan/MagicWE2/commands/history/UndoCommand.php index cb55719c..da8476dc 100644 --- a/src/xenialdan/MagicWE2/commands/history/UndoCommand.php +++ b/src/xenialdan/MagicWE2/commands/history/UndoCommand.php @@ -26,26 +26,27 @@ protected function prepare(): void { $this->setPermission("we.command.history.undo"); } + /** * @param CommandSender $sender * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $session = SessionHelper::getUserSession($sender); if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); diff --git a/src/xenialdan/MagicWE2/commands/selection/HPos1Command.php b/src/xenialdan/MagicWE2/commands/selection/HPos1Command.php index 3c5dfda4..bcfdcc69 100644 --- a/src/xenialdan/MagicWE2/commands/selection/HPos1Command.php +++ b/src/xenialdan/MagicWE2/commands/selection/HPos1Command.php @@ -34,42 +34,42 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (!$session instanceof UserSession) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates - if (is_null($selection)) { - throw new Error("No selection created - Check the console for errors"); - } - $target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance()); - if ($target === null) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget')); - return; - } - $selection->setPos1($target->getPos()); - } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + } + $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates + if (is_null($selection)) { + throw new Error("No selection created - Check the console for errors"); + } + $target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance()); + if ($target === null) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget')); + return; + } + $selection->setPos1($target->getPos()); + } catch (Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/selection/HPos2Command.php b/src/xenialdan/MagicWE2/commands/selection/HPos2Command.php index e813db0f..a217a941 100644 --- a/src/xenialdan/MagicWE2/commands/selection/HPos2Command.php +++ b/src/xenialdan/MagicWE2/commands/selection/HPos2Command.php @@ -34,42 +34,42 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (!$session instanceof UserSession) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates - if (is_null($selection)) { - throw new Error("No selection created - Check the console for errors"); - } - $target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance()); - if ($target === null) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget')); - return; - } - $selection->setPos2($target->getPos()); - } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + } + $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates + if (is_null($selection)) { + throw new Error("No selection created - Check the console for errors"); + } + $target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance()); + if ($target === null) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget')); + return; + } + $selection->setPos2($target->getPos()); + } catch (Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/selection/Pos1Command.php b/src/xenialdan/MagicWE2/commands/selection/Pos1Command.php index 85d21d2f..b95a1bef 100644 --- a/src/xenialdan/MagicWE2/commands/selection/Pos1Command.php +++ b/src/xenialdan/MagicWE2/commands/selection/Pos1Command.php @@ -34,37 +34,37 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (!$session instanceof UserSession) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates - if (is_null($selection)) { - throw new Error("No selection created - Check the console for errors"); - } - $selection->setPos1($sender->getPosition()); - } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + } + $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates + if (is_null($selection)) { + throw new Error("No selection created - Check the console for errors"); + } + $selection->setPos1($sender->getPosition()); + } catch (Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/selection/Pos2Command.php b/src/xenialdan/MagicWE2/commands/selection/Pos2Command.php index 3667021c..d3e2d781 100644 --- a/src/xenialdan/MagicWE2/commands/selection/Pos2Command.php +++ b/src/xenialdan/MagicWE2/commands/selection/Pos2Command.php @@ -34,37 +34,37 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (!$session instanceof UserSession) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (!$session instanceof UserSession) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates - if (is_null($selection)) { - throw new Error("No selection created - Check the console for errors"); - } - $selection->setPos2($sender->getPosition()); - } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + } + $selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($session->getUUID(), $sender->getWorld())); // TODO check if the selection inside of the session updates + if (is_null($selection)) { + throw new Error("No selection created - Check the console for errors"); + } + $selection->setPos2($sender->getPosition()); + } catch (Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/selection/info/ListChunksCommand.php b/src/xenialdan/MagicWE2/commands/selection/info/ListChunksCommand.php index 00c577e7..c5de7b0d 100644 --- a/src/xenialdan/MagicWE2/commands/selection/info/ListChunksCommand.php +++ b/src/xenialdan/MagicWE2/commands/selection/info/ListChunksCommand.php @@ -34,38 +34,38 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); - } - if (!$selection->isValid()) { + } + if (!$selection->isValid()) { throw new SelectionException($lang->translateString('error.selectioninvalid')); - } - if ($selection->getWorld() !== $sender->getWorld()) { + } + if ($selection->getWorld() !== $sender->getWorld()) { $sender->sendMessage(Loader::PREFIX . TF::GOLD . $lang->translateString('warning.differentworld')); - } - $touchedChunks = $selection->getShape()->getTouchedChunks($selection->getWorld()); - $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.listchunks.found', [count($touchedChunks)])); - foreach ($touchedChunks as $chunkHash => $touchedChunk) { + } + $touchedChunks = $selection->getShape()->getTouchedChunks($selection->getWorld()); + $session->sendMessage(TF::DARK_AQUA . $lang->translateString('command.listchunks.found', [count($touchedChunks)])); + foreach ($touchedChunks as $chunkHash => $touchedChunk) { $chunk = FastChunkSerializer::deserialize($touchedChunk); $biomes = []; for ($x = 0; $x < 16; $x++) diff --git a/src/xenialdan/MagicWE2/commands/selection/info/SizeCommand.php b/src/xenialdan/MagicWE2/commands/selection/info/SizeCommand.php index 9e505846..4c1e0b04 100644 --- a/src/xenialdan/MagicWE2/commands/selection/info/SizeCommand.php +++ b/src/xenialdan/MagicWE2/commands/selection/info/SizeCommand.php @@ -32,32 +32,32 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { throw new SelectionException($lang->translateString('error.noselection')); - } - if (!$selection->isValid()) { + } + if (!$selection->isValid()) { throw new SelectionException($lang->translateString('error.selectioninvalid')); - } + } if ($selection->getWorld() !== $sender->getWorld()) { $sender->sendMessage(Loader::PREFIX . TF::GOLD . $lang->translateString('warning.differentworld')); } diff --git a/src/xenialdan/MagicWE2/commands/tool/DebugCommand.php b/src/xenialdan/MagicWE2/commands/tool/DebugCommand.php index f4114fa8..c985a19b 100644 --- a/src/xenialdan/MagicWE2/commands/tool/DebugCommand.php +++ b/src/xenialdan/MagicWE2/commands/tool/DebugCommand.php @@ -37,21 +37,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $item = ItemFactory::getInstance()->get(ItemIds::STICK); $item->addEnchantment(new EnchantmentInstance(Loader::$ench)); $item->setCustomName(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('tool.debug')); @@ -63,12 +63,12 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $item->getNamedTag()->setTag(API::TAG_MAGIC_WE, CompoundTag::create()); $sender->getInventory()->addItem($item); } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/tool/FloodCommand.php b/src/xenialdan/MagicWE2/commands/tool/FloodCommand.php index 581c81a5..edee3614 100644 --- a/src/xenialdan/MagicWE2/commands/tool/FloodCommand.php +++ b/src/xenialdan/MagicWE2/commands/tool/FloodCommand.php @@ -26,45 +26,45 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $sender->sendMessage(TF::RED . "TEMPORARILY DISABLED!"); - /* - if (!$sender instanceof Player) return; - /** @var Player $sender * / - $lang = Loader::getInstance()->getLanguage(); - try { - if ($sender instanceof Player) { - $form = new CustomForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.flood.title')); - $form->addElement(new Slider($lang->translateString('ui.flood.options.limit'), 0, 5000, 500.0)); - $form->addElement(new Input($lang->translateString('ui.flood.options.blocks'), $lang->translateString('ui.flood.options.blocks.placeholder'))); - $form->addElement(new Label($lang->translateString('ui.flood.options.label.infoapply'))); - $form->setCallable(function (Player $player, $data) use ($form) { - $item = ItemFactory::get(ItemIds::BUCKET, 1); - $item->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Loader::FAKE_ENCH_ID))); - $item->setCustomName(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . 'Flood'); - $item->setLore(BrushCommand::generateLore($form->getContent(), $data)); - $item->setNamedTagEntry(new CompoundTag(API::TAG_MAGIC_WE, [ - new StringTag("blocks", $data[1]), - new FloatTag("limit", $data[0]), - ])); - $player->getInventory()->addItem($item); - }); - $sender->sendForm($form); - } else { - $sender->sendMessage(TF::RED . "Console can not use this command."); - } - } catch (\Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . Loader::getInstance()->getLanguage()->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (\ArgumentCountError $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . Loader::getInstance()->getLanguage()->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (\Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - }*/ - } + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $sender->sendMessage(TF::RED . "TEMPORARILY DISABLED!"); + /* + if (!$sender instanceof Player) return; + /** @var Player $sender * / + $lang = Loader::getInstance()->getLanguage(); + try { + if ($sender instanceof Player) { + $form = new CustomForm(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $lang->translateString('ui.flood.title')); + $form->addElement(new Slider($lang->translateString('ui.flood.options.limit'), 0, 5000, 500.0)); + $form->addElement(new Input($lang->translateString('ui.flood.options.blocks'), $lang->translateString('ui.flood.options.blocks.placeholder'))); + $form->addElement(new Label($lang->translateString('ui.flood.options.label.infoapply'))); + $form->setCallable(function (Player $player, $data) use ($form) { + $item = ItemFactory::get(ItemIds::BUCKET, 1); + $item->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Loader::FAKE_ENCH_ID))); + $item->setCustomName(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . 'Flood'); + $item->setLore(BrushCommand::generateLore($form->getContent(), $data)); + $item->setNamedTagEntry(new CompoundTag(API::TAG_MAGIC_WE, [ + new StringTag("blocks", $data[1]), + new FloatTag("limit", $data[0]), + ])); + $player->getInventory()->addItem($item); + }); + $sender->sendForm($form); + } else { + $sender->sendMessage(TF::RED . "Console can not use this command."); + } + } catch (\Exception $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . Loader::getInstance()->getLanguage()->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (\ArgumentCountError $error) { + $sender->sendMessage(Loader::PREFIX . TF::RED . Loader::getInstance()->getLanguage()->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (\Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + }*/ + } } diff --git a/src/xenialdan/MagicWE2/commands/tool/ToggledebugCommand.php b/src/xenialdan/MagicWE2/commands/tool/ToggledebugCommand.php index 9e4b44bb..ddfa6c8b 100644 --- a/src/xenialdan/MagicWE2/commands/tool/ToggledebugCommand.php +++ b/src/xenialdan/MagicWE2/commands/tool/ToggledebugCommand.php @@ -30,21 +30,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $session = SessionHelper::getUserSession($sender); if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); diff --git a/src/xenialdan/MagicWE2/commands/tool/TogglewandCommand.php b/src/xenialdan/MagicWE2/commands/tool/TogglewandCommand.php index f17861dc..053e18d9 100644 --- a/src/xenialdan/MagicWE2/commands/tool/TogglewandCommand.php +++ b/src/xenialdan/MagicWE2/commands/tool/TogglewandCommand.php @@ -30,21 +30,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { $session = SessionHelper::getUserSession($sender); if (is_null($session)) { throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); diff --git a/src/xenialdan/MagicWE2/commands/tool/WandCommand.php b/src/xenialdan/MagicWE2/commands/tool/WandCommand.php index 8177e95c..591bc32e 100644 --- a/src/xenialdan/MagicWE2/commands/tool/WandCommand.php +++ b/src/xenialdan/MagicWE2/commands/tool/WandCommand.php @@ -38,21 +38,21 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { /** @var Durable $item */ $item = ItemFactory::getInstance()->get(ItemIds::WOODEN_AXE); $item->addEnchantment(new EnchantmentInstance(Loader::$ench)); @@ -66,12 +66,12 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $item->getNamedTag()->setTag(API::TAG_MAGIC_WE, CompoundTag::create()); if (!$sender->getInventory()->contains($item)) $sender->getInventory()->addItem($item); } catch (Exception $error) { - $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - $sender->sendMessage($this->getUsage()); - } catch (Error $error) { - Loader::getInstance()->getLogger()->logException($error); - $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); - } - } + $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + $sender->sendMessage($this->getUsage()); + } catch (Error $error) { + Loader::getInstance()->getLogger()->logException($error); + $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); + } + } } diff --git a/src/xenialdan/MagicWE2/commands/utility/CalculateCommand.php b/src/xenialdan/MagicWE2/commands/utility/CalculateCommand.php index 113c1e56..d8687873 100644 --- a/src/xenialdan/MagicWE2/commands/utility/CalculateCommand.php +++ b/src/xenialdan/MagicWE2/commands/utility/CalculateCommand.php @@ -37,15 +37,15 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } try { $sender->sendMessage((string)$args["expression"] . " = " . API::evalAsMath((string)$args["expression"])); } catch (CalculationException $error) { diff --git a/src/xenialdan/MagicWE2/event/MWEEditEvent.php b/src/xenialdan/MagicWE2/event/MWEEditEvent.php index 503ebecc..004b011e 100644 --- a/src/xenialdan/MagicWE2/event/MWEEditEvent.php +++ b/src/xenialdan/MagicWE2/event/MWEEditEvent.php @@ -30,54 +30,54 @@ class MWEEditEvent extends MWEEvent implements Cancellable */ public function __construct(Plugin $plugin, array $oldBlocks, array $newBlocks, ?Session $session) { - parent::__construct($plugin); - $this->oldBlocks = $oldBlocks; - $this->newBlocks = $newBlocks; - $this->session = $session; - } + parent::__construct($plugin); + $this->oldBlocks = $oldBlocks; + $this->newBlocks = $newBlocks; + $this->session = $session; + } - /** - * @return null|Session - */ - public function getSession(): ?Session - { - return $this->session; - } + /** + * @return null|Session + */ + public function getSession(): ?Session + { + return $this->session; + } - /** - * @return null|Player - */ - public function getPlayer(): ?Player - { - if (($session = $this->getSession()) instanceof UserSession) - /** @var UserSession $session */ - return $session->getPlayer(); - return null; - } + /** + * @return null|Player + */ + public function getPlayer(): ?Player + { + if (($session = $this->getSession()) instanceof UserSession) + /** @var UserSession $session */ + return $session->getPlayer(); + return null; + } - /** - * @param null|Player $player - */ - public function setPlayer(?Player $player): void - { - if (($session = $this->getSession()) instanceof UserSession) - /** @var UserSession $session */ - $session->setPlayer($player); - } + /** + * @param null|Player $player + */ + public function setPlayer(?Player $player): void + { + if (($session = $this->getSession()) instanceof UserSession) + /** @var UserSession $session */ + $session->setPlayer($player); + } - /** - * @return Block[] - */ - public function getOldBlocks(): array - { - return $this->oldBlocks; - } + /** + * @return Block[] + */ + public function getOldBlocks(): array + { + return $this->oldBlocks; + } - /** - * @return Block[] - */ - public function getNewBlocks(): array - { + /** + * @return Block[] + */ + public function getNewBlocks(): array + { return $this->newBlocks; } diff --git a/src/xenialdan/MagicWE2/event/MWESelectionChangeEvent.php b/src/xenialdan/MagicWE2/event/MWESelectionChangeEvent.php index 6cdbe748..6fa42f2f 100644 --- a/src/xenialdan/MagicWE2/event/MWESelectionChangeEvent.php +++ b/src/xenialdan/MagicWE2/event/MWESelectionChangeEvent.php @@ -49,15 +49,15 @@ public function setSelection(Selection $selection): void $this->selection = $selection; } - /** - * @return null|Session - */ - public function getSession(): ?Session - { - return $this->session; - } + /** + * @return null|Session + */ + public function getSession(): ?Session + { + return $this->session; + } - /** + /** * @return null|Player */ public function getPlayer(): ?Player diff --git a/src/xenialdan/MagicWE2/helper/AsyncChunkManager.php b/src/xenialdan/MagicWE2/helper/AsyncChunkManager.php index 4ef07060..d05e0d1f 100644 --- a/src/xenialdan/MagicWE2/helper/AsyncChunkManager.php +++ b/src/xenialdan/MagicWE2/helper/AsyncChunkManager.php @@ -8,16 +8,16 @@ class AsyncChunkManager extends SimpleChunkManager { - public function getBlockArrayAt(int $x, int $y, int $z): array//TODO replace with getFullBlock + public function getBlockArrayAt(int $x, int $y, int $z): array//TODO replace with getFullBlock { return [$this->getBlockAt($x, $y, $z)->getId(), $this->getBlockAt($x, $y, $z)->getMeta()]; } - /** - * @return Chunk[] - */ - public function getChunks(): array - { - return $this->chunks; - } + /** + * @return Chunk[] + */ + public function getChunks(): array + { + return $this->chunks; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/helper/BlockQuery.php b/src/xenialdan/MagicWE2/helper/BlockQuery.php index 1cda2c2c..dce14490 100644 --- a/src/xenialdan/MagicWE2/helper/BlockQuery.php +++ b/src/xenialdan/MagicWE2/helper/BlockQuery.php @@ -42,7 +42,7 @@ public function parse(bool $update = true): self /** @var BlockStatesParser $blockstateParser */ $blockstateParser = BlockStatesParser::getInstance(); $blockstateParser::fromString($this);//this should already set the blockFullId because it is a reference - var_dump($this->hasBlock() ? "Has block, " . $this->blockFullId : "Does not have block"); + //var_dump($this->hasBlock() ? "Has block, " . $this->blockFullId : "Does not have block"); //TODO throw BlockQueryParsingFailedException if blockFullId was not set? `if(!$this->hasBlock())` return $this; } diff --git a/src/xenialdan/MagicWE2/helper/Progress.php b/src/xenialdan/MagicWE2/helper/Progress.php index 41d2690e..fc67e892 100644 --- a/src/xenialdan/MagicWE2/helper/Progress.php +++ b/src/xenialdan/MagicWE2/helper/Progress.php @@ -20,10 +20,10 @@ public function __construct(float $progress, string $info) { $this->progress = $progress; $this->string = $info; - } + } - public function __toString() - { - return "Progress: " . $this->progress . " String: " . $this->string; - } + public function __toString() + { + return "Progress: " . $this->progress . " String: " . $this->string; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/helper/Scoreboard.php b/src/xenialdan/MagicWE2/helper/Scoreboard.php index d2d782e2..a980eb31 100644 --- a/src/xenialdan/MagicWE2/helper/Scoreboard.php +++ b/src/xenialdan/MagicWE2/helper/Scoreboard.php @@ -11,6 +11,7 @@ use pocketmine\utils\TextFormat as TF; use ReflectionClass; use ReflectionException; +use xenialdan\MagicWE2\API; use xenialdan\MagicWE2\clipboard\SingleClipboard; use xenialdan\MagicWE2\Loader; use xenialdan\MagicWE2\selection\Selection; @@ -28,18 +29,18 @@ public function handleScoreboard(UserSession $session): void $line = 0; $selection = $session->getLatestSelection(); ScoreFactory::setScoreLine($player, ++$line, TF::GOLD . $session->getLanguage()->translateString("spacer", ["Selection"])); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Position: " . TF::RESET . "{$this->vecToString($selection->getPos1()->asVector3())} » {$this->vecToString($selection->getPos2()->asVector3())}"); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Position: " . TF::RESET . API::vecToString($selection->getPos1()->asVector3()) . " » " . API::vecToString($selection->getPos2()->asVector3())); ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "World: " . TF::RESET . $selection->getWorld()->getFolderName()); ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Shape: " . TF::RESET . (new ReflectionClass($selection->shape))->getShortName()); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Size: " . TF::RESET . "{$this->vecToString(new Vector3($selection->getSizeX(),$selection->getSizeY(),$selection->getSizeZ()))} ({$selection->getShape()->getTotalCount()})"); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Size: " . TF::RESET . API::vecToString(new Vector3($selection->getSizeX(), $selection->getSizeY(), $selection->getSizeZ())) . " ({$selection->getShape()->getTotalCount()})"); ScoreFactory::setScoreLine($player, ++$line, TF::GOLD . $session->getLanguage()->translateString("spacer", ["Settings"])); ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Tool Range: " . TF::RESET . Loader::getInstance()->getToolDistance()); $editLimit = Loader::getInstance()->getEditLimit(); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Limit: " . TF::RESET . ($editLimit === -1 ? $this->boolToString(false) : $editLimit)); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Wand Tool: " . TF::RESET . $this->boolToString($session->isWandEnabled())); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Debug Tool: " . TF::RESET . $this->boolToString($session->isDebugToolEnabled())); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "WAILA: " . TF::RESET . $this->boolToString($session->isWailaEnabled())); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Limit: " . TF::RESET . ($editLimit === -1 ? API::boolToString(false) : $editLimit)); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Wand Tool: " . TF::RESET . API::boolToString($session->isWandEnabled())); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Debug Tool: " . TF::RESET . API::boolToString($session->isDebugToolEnabled())); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "WAILA: " . TF::RESET . API::boolToString($session->isWailaEnabled())); if (($cb = $session->getCurrentClipboard()) instanceof SingleClipboard) { ScoreFactory::setScoreLine($player, ++$line, TF::GOLD . $session->getLanguage()->translateString("spacer", ["Clipboard"])); @@ -48,7 +49,7 @@ public function handleScoreboard(UserSession $session): void ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Name: " . TF::RESET . $cb->customName); if ($cb->selection instanceof Selection) { ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Shape: " . TF::RESET . (new ReflectionClass($cb->selection->shape))->getShortName()); - ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Size: " . TF::RESET . "{$this->vecToString(new Vector3($cb->selection->getSizeX(),$cb->selection->getSizeY(),$cb->selection->getSizeZ()))} ({$cb->getTotalCount()})"); + ScoreFactory::setScoreLine($player, ++$line, TF::ITALIC . "Size: " . TF::RESET . API::vecToString(new Vector3($cb->selection->getSizeX(), $cb->selection->getSizeY(), $cb->selection->getSizeZ())) . " ({$cb->getTotalCount()})"); } } //todo current block palette, schematics, brushes @@ -57,14 +58,4 @@ public function handleScoreboard(UserSession $session): void } } } - - private function vecToString(Vector3 $v): string - { - return TF::RESET . "[" . TF::RED . $v->getFloorX() . TF::RESET . ":" . TF::GREEN . $v->getFloorY() . TF::RESET . ":" . TF::BLUE . $v->getFloorZ() . TF::RESET . "]"; - } - - private function boolToString(bool $b): string - { - return $b ? TF::RESET . TF::GREEN . "On" . TF::RESET : TF::RESET . TF::RED . "Off" . TF::RESET; - } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/helper/StructureStore.php b/src/xenialdan/MagicWE2/helper/StructureStore.php index 8a271328..969f7192 100644 --- a/src/xenialdan/MagicWE2/helper/StructureStore.php +++ b/src/xenialdan/MagicWE2/helper/StructureStore.php @@ -28,8 +28,7 @@ final class StructureStore /** @noinspection MkdirRaceConditionInspection */ public function __construct() { - @mkdir(Loader::getInstance()->getDataFolder() . 'structures'); - @mkdir(Loader::getInstance()->getDataFolder() . 'schematics'); + @mkdir(Loader::getInstance()->getDataFolder() . 'assets'); } /** @@ -44,9 +43,8 @@ public function loadStructure(string $filename, bool $override = true): MCStruct { $id = pathinfo($filename, PATHINFO_FILENAME); if (!$override && array_key_exists($id, $this->structures)) throw new InvalidArgumentException("Can not override $id"); - $path = Loader::getInstance()->getDataFolder() . 'structures' . DIRECTORY_SEPARATOR . $id . '.mcstructure';//TODO redundant? + $path = Loader::getInstance()->getDataFolder() . 'assets' . DIRECTORY_SEPARATOR . $id . '.mcstructure'; $structure = new MCStructure(); - $structure->parse($path); $this->structures[$id] = $structure; return $this->structures[$id]; @@ -76,7 +74,7 @@ public function loadSchematic(string $filename, bool $override = true): Schemati { $id = pathinfo($filename, PATHINFO_FILENAME); if (!$override && array_key_exists($id, $this->schematics)) throw new InvalidArgumentException("Can not override $id"); - $path = Loader::getInstance()->getDataFolder() . 'schematics' . DIRECTORY_SEPARATOR . $id . '.schematic'; + $path = Loader::getInstance()->getDataFolder() . 'assets' . DIRECTORY_SEPARATOR . $id . '.schematic'; $schematic = new Schematic(); $schematic->parse($path); $this->schematics[$id] = $schematic; diff --git a/src/xenialdan/MagicWE2/selection/shape/Cube.php b/src/xenialdan/MagicWE2/selection/shape/Cube.php index 70cc3082..acc3779e 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Cube.php +++ b/src/xenialdan/MagicWE2/selection/shape/Cube.php @@ -54,9 +54,9 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API } } } - } - } - } + } + } + } /** * Returns a flat layer of all included x z positions in selection @@ -65,7 +65,7 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API * @return Generator|Vector2[] * @throws Exception */ - public function getLayer($manager, int $flags = API::FLAG_BASE): Generator + public function getLayer($manager, int $flags = API::FLAG_BASE): Generator { $this->validateChunkManager($manager); for ($x = (int)floor($this->getMinVec3()->x); $x <= floor($this->getMaxVec3()->x); $x++) { @@ -75,13 +75,13 @@ public function getLayer($manager, int $flags = API::FLAG_BASE): Generator } } - /** - * @param World|AsyncChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - public function getTouchedChunks($manager): array - { + /** + * @param World|AsyncChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + public function getTouchedChunks($manager): array + { $this->validateChunkManager($manager); $maxX = ($this->getMaxVec3()->x + 1) >> 4; $minX = $this->getMinVec3()->x >> 4; @@ -97,30 +97,30 @@ public function getTouchedChunks($manager): array print "Touched Chunk at: $x:$z" . PHP_EOL; $touchedChunks[World::chunkHash($x, $z)] = FastChunkSerializer::serialize($chunk); } - } - print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; - return $touchedChunks; - } + } + print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; + return $touchedChunks; + } - public function getAABB(): AxisAlignedBB - { - return new AxisAlignedBB( - ceil($this->pasteVector->x - $this->width / 2), - $this->pasteVector->y, - ceil($this->pasteVector->z - $this->width / 2), - -1 + ceil($this->pasteVector->x - $this->width / 2) + $this->width, - -1 + $this->pasteVector->y + $this->width, - -1 + ceil($this->pasteVector->z - $this->width / 2) + $this->width - ); - } + public function getAABB(): AxisAlignedBB + { + return new AxisAlignedBB( + ceil($this->pasteVector->x - $this->width / 2), + $this->pasteVector->y, + ceil($this->pasteVector->z - $this->width / 2), + -1 + ceil($this->pasteVector->x - $this->width / 2) + $this->width, + -1 + $this->pasteVector->y + $this->width, + -1 + ceil($this->pasteVector->z - $this->width / 2) + $this->width + ); + } - public function getTotalCount(): int - { - return $this->width ** 3; - } + public function getTotalCount(): int + { + return $this->width ** 3; + } - public static function getName(): string - { - return "Cube"; - } + public static function getName(): string + { + return "Cube"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/selection/shape/Cuboid.php b/src/xenialdan/MagicWE2/selection/shape/Cuboid.php index 623ba9a1..6189615a 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Cuboid.php +++ b/src/xenialdan/MagicWE2/selection/shape/Cuboid.php @@ -33,14 +33,14 @@ class Cuboid extends Shape */ public function __construct(Vector3 $pasteVector, int $width, int $height, int $depth) { - $this->pasteVector = $pasteVector; - $this->width = $width; - $this->height = $height; - $this->depth = $depth; - } + $this->pasteVector = $pasteVector; + $this->width = $width; + $this->height = $height; + $this->depth = $depth; + } - public static function constructFromPositions(Vector3 $pos1, Vector3 $pos2): self - { + public static function constructFromPositions(Vector3 $pos1, Vector3 $pos2): self + { $width = (int)abs($pos1->getX() - $pos2->getX()) + 1; $height = (int)abs($pos1->getY() - $pos2->getY()) + 1; $depth = (int)abs($pos1->getZ() - $pos2->getZ()) + 1; @@ -76,9 +76,9 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API } } } - } - } - } + } + } + } /** * Returns a flat layer of all included x z positions in selection @@ -87,7 +87,7 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API * @return Generator|Vector2[] * @throws Exception */ - public function getLayer($manager, int $flags = API::FLAG_BASE): Generator + public function getLayer($manager, int $flags = API::FLAG_BASE): Generator { $this->validateChunkManager($manager); for ($x = (int)floor($this->getMinVec3()->x); $x <= floor($this->getMaxVec3()->x); $x++) { @@ -97,13 +97,13 @@ public function getLayer($manager, int $flags = API::FLAG_BASE): Generator } } - /** - * @param World|AsyncChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - public function getTouchedChunks($manager): array - { + /** + * @param World|AsyncChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + public function getTouchedChunks($manager): array + { $this->validateChunkManager($manager); $maxX = ($this->getMaxVec3()->x + 1) >> 4; $minX = $this->getMinVec3()->x >> 4; @@ -119,31 +119,31 @@ public function getTouchedChunks($manager): array $touchedChunks[World::chunkHash($x, $z)] = FastChunkSerializer::serialize($chunk); } } - return $touchedChunks; - } + return $touchedChunks; + } - public function getAABB(): AxisAlignedBB - { - return new AxisAlignedBB( - ceil($this->pasteVector->x - $this->width / 2), - $this->pasteVector->y, - ceil($this->pasteVector->z - $this->depth / 2), - -1 + ceil($this->pasteVector->x - $this->width / 2) + $this->width, - -1 + $this->pasteVector->y + $this->height, - -1 + ceil($this->pasteVector->z - $this->depth / 2) + $this->depth - ); - } + public function getAABB(): AxisAlignedBB + { + return new AxisAlignedBB( + ceil($this->pasteVector->x - $this->width / 2), + $this->pasteVector->y, + ceil($this->pasteVector->z - $this->depth / 2), + -1 + ceil($this->pasteVector->x - $this->width / 2) + $this->width, + -1 + $this->pasteVector->y + $this->height, + -1 + ceil($this->pasteVector->z - $this->depth / 2) + $this->depth + ); + } - /** - * @return int - */ - public function getTotalCount(): int - { - return $this->width * $this->height * $this->depth; - } + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->width * $this->height * $this->depth; + } - public static function getName(): string - { - return "Cuboid"; - } + public static function getName(): string + { + return "Cuboid"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/selection/shape/Cylinder.php b/src/xenialdan/MagicWE2/selection/shape/Cylinder.php index 6eec93a0..c5b7a947 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Cylinder.php +++ b/src/xenialdan/MagicWE2/selection/shape/Cylinder.php @@ -31,9 +31,9 @@ class Cylinder extends Shape public function __construct(Vector3 $pasteVector, int $height, int $diameter) { $this->pasteVector = $pasteVector; - $this->height = $height; - $this->diameter = $diameter; - } + $this->height = $height; + $this->diameter = $diameter; + } /** * Returns the blocks by their actual position @@ -67,9 +67,9 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API } } } - } - } - } + } + } + } /** * Returns a flat layer of all included x z positions in selection @@ -78,7 +78,7 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API * @return Generator|Vector2[] * @throws Exception */ - public function getLayer($manager, int $flags = API::FLAG_BASE): Generator + public function getLayer($manager, int $flags = API::FLAG_BASE): Generator { $this->validateChunkManager($manager); $centerVec2 = new Vector2($this->getPasteVector()->getX(), $this->getPasteVector()->getZ()); @@ -92,13 +92,13 @@ public function getLayer($manager, int $flags = API::FLAG_BASE): Generator } } - /** - * @param World|AsyncChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - public function getTouchedChunks($manager): array - {//TODO optimize to remove "corner" chunks + /** + * @param World|AsyncChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + public function getTouchedChunks($manager): array + {//TODO optimize to remove "corner" chunks $this->validateChunkManager($manager); $maxX = ($this->getMaxVec3()->x + 1) >> 4; $minX = $this->getMinVec3()->x >> 4; @@ -114,30 +114,30 @@ public function getTouchedChunks($manager): array print "Touched Chunk at: $x:$z" . PHP_EOL; $touchedChunks[World::chunkHash($x, $z)] = FastChunkSerializer::serialize($chunk); } - } - print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; - return $touchedChunks; - } + } + print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; + return $touchedChunks; + } - public function getAABB(): AxisAlignedBB - { - return new AxisAlignedBB( - floor($this->pasteVector->x - $this->diameter / 2), - $this->pasteVector->y, - floor($this->pasteVector->z - $this->diameter / 2), - -1 + floor($this->pasteVector->x - $this->diameter / 2) + $this->diameter, - -1 + $this->pasteVector->y + $this->height, - -1 + floor($this->pasteVector->z - $this->diameter / 2) + $this->diameter - ); - } + public function getAABB(): AxisAlignedBB + { + return new AxisAlignedBB( + floor($this->pasteVector->x - $this->diameter / 2), + $this->pasteVector->y, + floor($this->pasteVector->z - $this->diameter / 2), + -1 + floor($this->pasteVector->x - $this->diameter / 2) + $this->diameter, + -1 + $this->pasteVector->y + $this->height, + -1 + floor($this->pasteVector->z - $this->diameter / 2) + $this->diameter + ); + } - public function getTotalCount(): int - { + public function getTotalCount(): int + { return (int)ceil(M_PI * (($this->diameter / 2) ** 2) * $this->height); - } + } - public static function getName(): string - { - return "Cylinder"; - } + public static function getName(): string + { + return "Cylinder"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/selection/shape/Ellipsoid.php b/src/xenialdan/MagicWE2/selection/shape/Ellipsoid.php index a414815f..68cd59d3 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Ellipsoid.php +++ b/src/xenialdan/MagicWE2/selection/shape/Ellipsoid.php @@ -33,11 +33,11 @@ class Ellipsoid extends Shape */ public function __construct(Vector3 $pasteVector, int $width, int $height, int $depth) { - $this->pasteVector = $pasteVector; - $this->width = $width; - $this->height = $height; - $this->depth = $depth; - } + $this->pasteVector = $pasteVector; + $this->width = $width; + $this->height = $height; + $this->depth = $depth; + } /** * Returns the blocks by their actual position @@ -58,12 +58,12 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API $zrad = $this->depth / 2; $xradSquared = $xrad ** 2; $yradSquared = $yrad ** 2; - $zradSquared = $zrad ** 2; - $targetX = $this->pasteVector->getX(); - $targetY = $this->pasteVector->getY(); - $targetZ = $this->pasteVector->getZ(); + $zradSquared = $zrad ** 2; + $targetX = $this->pasteVector->getX(); + $targetY = $this->pasteVector->getY(); + $targetZ = $this->pasteVector->getZ(); - for ($x = (int)floor($centerVec2->x - $this->width / 2 /*- 1*/); $x <= floor($centerVec2->x + $this->width / 2 /*+ 1*/); $x++) { + for ($x = (int)floor($centerVec2->x - $this->width / 2 /*- 1*/); $x <= floor($centerVec2->x + $this->width / 2 /*+ 1*/); $x++) { $xSquared = ($targetX - $x) ** 2; for ($y = (int)floor($this->getPasteVector()->y) + 1, $ry = 0; $y <= floor($this->getPasteVector()->y + $this->height); $y++, $ry++) { $ySquared = ($targetY - $y + $yrad) ** 2; @@ -86,9 +86,9 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API } } } - } - } - } + } + } + } /** * Returns a flat layer of all included x z positions in selection @@ -97,17 +97,17 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API * @return Generator|Vector2[] * @throws Exception */ - public function getLayer($manager, int $flags = API::FLAG_BASE): Generator - { - $this->validateChunkManager($manager); - $centerVec2 = new Vector2($this->getPasteVector()->getX(), $this->getPasteVector()->getZ()); - - $xrad = $this->width / 2; - $zrad = $this->depth / 2; - $xradSquared = $xrad ** 2; - $zradSquared = $zrad ** 2; - $targetX = $this->pasteVector->getX(); - $targetZ = $this->pasteVector->getZ(); + public function getLayer($manager, int $flags = API::FLAG_BASE): Generator + { + $this->validateChunkManager($manager); + $centerVec2 = new Vector2($this->getPasteVector()->getX(), $this->getPasteVector()->getZ()); + + $xrad = $this->width / 2; + $zrad = $this->depth / 2; + $xradSquared = $xrad ** 2; + $zradSquared = $zrad ** 2; + $targetX = $this->pasteVector->getX(); + $targetZ = $this->pasteVector->getZ(); for ($x = (int)floor($centerVec2->x - $this->width / 2 /*- 1*/); $x <= floor($centerVec2->x + $this->width / 2 /*+ 1*/); $x++) { $xSquared = ($targetX - $x) ** 2; @@ -118,15 +118,15 @@ public function getLayer($manager, int $flags = API::FLAG_BASE): Generator yield new Vector2($x, $z); } } - } - - /** - * @param World|AsyncChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - public function getTouchedChunks($manager): array - {//TODO optimize to remove "corner" chunks + } + + /** + * @param World|AsyncChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + public function getTouchedChunks($manager): array + {//TODO optimize to remove "corner" chunks $this->validateChunkManager($manager); $maxX = ($this->getMaxVec3()->x + 1) >> 4; $minX = $this->getMinVec3()->x >> 4; @@ -142,30 +142,30 @@ public function getTouchedChunks($manager): array print "Touched Chunk at: $x:$z" . PHP_EOL; $touchedChunks[World::chunkHash($x, $z)] = FastChunkSerializer::serialize($chunk); } - } - print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; - return $touchedChunks; - } - - public function getAABB(): AxisAlignedBB - { - return new AxisAlignedBB( - floor($this->pasteVector->x - $this->width / 2), - $this->pasteVector->y, - floor($this->pasteVector->z - $this->depth / 2), - -1 + floor($this->pasteVector->x - $this->width / 2) + $this->width, - -1 + $this->pasteVector->y + $this->height, - -1 + floor($this->pasteVector->z - $this->depth / 2) + $this->depth - ); - } - - public function getTotalCount(): int - { + } + print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; + return $touchedChunks; + } + + public function getAABB(): AxisAlignedBB + { + return new AxisAlignedBB( + floor($this->pasteVector->x - $this->width / 2), + $this->pasteVector->y, + floor($this->pasteVector->z - $this->depth / 2), + -1 + floor($this->pasteVector->x - $this->width / 2) + $this->width, + -1 + $this->pasteVector->y + $this->height, + -1 + floor($this->pasteVector->z - $this->depth / 2) + $this->depth + ); + } + + public function getTotalCount(): int + { return (int)floor(4 * M_PI * (($this->width / 2) + 1) * (($this->height / 2) + 1) * (($this->depth / 2) + 1) / 3); - } + } - public static function getName(): string - { - return "Ellipsoid"; - } + public static function getName(): string + { + return "Ellipsoid"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/selection/shape/Pyramid.php b/src/xenialdan/MagicWE2/selection/shape/Pyramid.php index 1e50d505..2a0cf42e 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Pyramid.php +++ b/src/xenialdan/MagicWE2/selection/shape/Pyramid.php @@ -35,13 +35,13 @@ class Pyramid extends Shape * @param bool $flipped */ public function __construct(Vector3 $pasteVector, int $width, int $height, int $depth, bool $flipped = false) - { - $this->pasteVector = $pasteVector; - $this->width = $width; - $this->height = $height; - $this->depth = $depth; - $this->flipped = $flipped; - } + { + $this->pasteVector = $pasteVector; + $this->width = $width; + $this->height = $height; + $this->depth = $depth; + $this->flipped = $flipped; + } /** * Returns the blocks by their actual position @@ -85,9 +85,9 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API } } } - } - } - } + } + } + } /** * Returns a flat layer of all included x z positions in selection @@ -96,7 +96,7 @@ public function getBlocks($manager, BlockPalette $filterblocks, int $flags = API * @return Generator|Vector2[] * @throws Exception */ - public function getLayer($manager, int $flags = API::FLAG_BASE): Generator + public function getLayer($manager, int $flags = API::FLAG_BASE): Generator { $this->validateChunkManager($manager); $centerVec2 = new Vector2($this->getPasteVector()->getX(), $this->getPasteVector()->getZ()); @@ -108,13 +108,13 @@ public function getLayer($manager, int $flags = API::FLAG_BASE): Generator } } - /** - * @param World|AsyncChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - public function getTouchedChunks($manager): array - {//TODO optimize to remove "corner" chunks + /** + * @param World|AsyncChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + public function getTouchedChunks($manager): array + {//TODO optimize to remove "corner" chunks $this->validateChunkManager($manager); $maxX = ($this->getMaxVec3()->x + 1) >> 4; $minX = $this->getMinVec3()->x >> 4; @@ -130,30 +130,30 @@ public function getTouchedChunks($manager): array print "Touched Chunk at: $x:$z" . PHP_EOL; $touchedChunks[World::chunkHash($x, $z)] = FastChunkSerializer::serialize($chunk); } - } - print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; - return $touchedChunks; - } + } + print "Touched chunks count: " . count($touchedChunks) . PHP_EOL; + return $touchedChunks; + } - public function getAABB(): AxisAlignedBB - { - return new AxisAlignedBB( - floor($this->pasteVector->x - $this->width / 2), - $this->pasteVector->y, - floor($this->pasteVector->z - $this->depth / 2), - -1 + floor($this->pasteVector->x - $this->width / 2) + $this->width, - -1 + $this->pasteVector->y + $this->height, - -1 + floor($this->pasteVector->z - $this->depth / 2) + $this->depth - ); - } + public function getAABB(): AxisAlignedBB + { + return new AxisAlignedBB( + floor($this->pasteVector->x - $this->width / 2), + $this->pasteVector->y, + floor($this->pasteVector->z - $this->depth / 2), + -1 + floor($this->pasteVector->x - $this->width / 2) + $this->width, + -1 + $this->pasteVector->y + $this->height, + -1 + floor($this->pasteVector->z - $this->depth / 2) + $this->depth + ); + } - public function getTotalCount(): int - { - return (int)ceil((1 / 3) * ($this->width * $this->depth) * $this->height); - } + public function getTotalCount(): int + { + return (int)ceil((1 / 3) * ($this->width * $this->depth) * $this->height); + } - public static function getName(): string - { - return "Pyramid"; - } + public static function getName(): string + { + return "Pyramid"; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/selection/shape/Shape.php b/src/xenialdan/MagicWE2/selection/shape/Shape.php index b8661d34..a0ee1b8d 100644 --- a/src/xenialdan/MagicWE2/selection/shape/Shape.php +++ b/src/xenialdan/MagicWE2/selection/shape/Shape.php @@ -32,13 +32,13 @@ public function setPasteVector(Vector3 $pasteVector): void $this->pasteVector = $pasteVector->asVector3(); } - /** - * Creates a chunk manager used for async editing - * @param Chunk[] $chunks - * @return AsyncChunkManager - */ - public static function getChunkManager(array $chunks): AsyncChunkManager - { + /** + * Creates a chunk manager used for async editing + * @param Chunk[] $chunks + * @return AsyncChunkManager + */ + public static function getChunkManager(array $chunks): AsyncChunkManager + { $manager = new AsyncChunkManager(); foreach ($chunks as $hash => $chunk) { World::getXZ($hash, $chunkX, $chunkZ); @@ -47,16 +47,16 @@ public static function getChunkManager(array $chunks): AsyncChunkManager return $manager; } - /** - * @param mixed $manager - * @throws InvalidArgumentException - */ - public function validateChunkManager($manager): void - { - if (!$manager instanceof World && !$manager instanceof AsyncChunkManager) throw new InvalidArgumentException(get_class($manager) . " is not an instance of World or AsyncChunkManager"); - } + /** + * @param mixed $manager + * @throws InvalidArgumentException + */ + public function validateChunkManager($manager): void + { + if (!$manager instanceof World && !$manager instanceof AsyncChunkManager) throw new InvalidArgumentException(get_class($manager) . " is not an instance of World or AsyncChunkManager"); + } - abstract public function getTotalCount(): int; + abstract public function getTotalCount(): int; /** * Returns the blocks by their actual position @@ -75,52 +75,52 @@ abstract public function getBlocks($manager, BlockPalette $filterblocks, int $fl * @return Generator|Vector2[] * @throws Exception */ - abstract public function getLayer($manager, int $flags = API::FLAG_BASE): Generator; - - /** - * @param ChunkManager $manager - * @return string[] fastSerialized chunks - * @throws Exception - */ - abstract public function getTouchedChunks(ChunkManager $manager): array; - - abstract public function getAABB(): AxisAlignedBB; - - /** - * @return Vector3 - */ - public function getMinVec3(): Vector3 - { - return new Vector3($this->getAABB()->minX, $this->getAABB()->minY, $this->getAABB()->minZ); - } - - /** - * @return Vector3 - */ - public function getMaxVec3(): Vector3 - { - return new Vector3($this->getAABB()->maxX, $this->getAABB()->maxY, $this->getAABB()->maxZ); - } - - abstract public static function getName(): string; - - public function getShapeProperties(): array - { + abstract public function getLayer($manager, int $flags = API::FLAG_BASE): Generator; + + /** + * @param ChunkManager $manager + * @return string[] fastSerialized chunks + * @throws Exception + */ + abstract public function getTouchedChunks(ChunkManager $manager): array; + + abstract public function getAABB(): AxisAlignedBB; + + /** + * @return Vector3 + */ + public function getMinVec3(): Vector3 + { + return new Vector3($this->getAABB()->minX, $this->getAABB()->minY, $this->getAABB()->minZ); + } + + /** + * @return Vector3 + */ + public function getMaxVec3(): Vector3 + { + return new Vector3($this->getAABB()->maxX, $this->getAABB()->maxY, $this->getAABB()->maxZ); + } + + abstract public static function getName(): string; + + public function getShapeProperties(): array + { return array_diff(get_object_vars($this), get_class_vars(__CLASS__)); - } - - /** - * String representation of object - * @link http://php.net/manual/en/serializable.serialize.php - * @return string the string representation of the object or null - * @since 5.1.0 - */ - public function serialize() - { - return serialize((array)$this); - } - - /** + } + + /** + * String representation of object + * @link http://php.net/manual/en/serializable.serialize.php + * @return string the string representation of the object or null + * @since 5.1.0 + */ + public function serialize() + { + return serialize((array)$this); + } + + /** * Constructs the object * @link http://php.net/manual/en/serializable.unserialize.php * @param string $serialized

@@ -130,8 +130,8 @@ public function serialize() * @since 5.1.0 * @noinspection PhpMissingParamTypeInspection */ - public function unserialize($serialized) - { + public function unserialize($serialized) + { $unserialize = unserialize($serialized/*, ['allowed_classes' => [__CLASS__]]*/);//TODO test pm4 array_walk($unserialize, function ($value, $key) { $this->$key = $value; diff --git a/src/xenialdan/MagicWE2/selection/shape/ShapeRegistry.php b/src/xenialdan/MagicWE2/selection/shape/ShapeRegistry.php index 7dfd1f74..d6279fbc 100644 --- a/src/xenialdan/MagicWE2/selection/shape/ShapeRegistry.php +++ b/src/xenialdan/MagicWE2/selection/shape/ShapeRegistry.php @@ -20,57 +20,57 @@ class ShapeRegistry//todo use SingletonTrait public const PYRAMID = "Pyramid"; public const ELLIPSOID = "Ellipsoid"; - public function __construct() - { - self::registerShape(self::SPHERE, Sphere::class); - self::registerShape(self::CUBE, Cube::class); - self::registerShape(self::CUBOID, Cuboid::class); - self::registerShape(self::CYLINDER, Cylinder::class); - self::registerShape(self::CONE, Cone::class); - self::registerShape(self::PYRAMID, Pyramid::class); - self::registerShape(self::ELLIPSOID, Ellipsoid::class); - self::registerShape(self::CUSTOM, Custom::class); - } + public function __construct() + { + self::registerShape(self::SPHERE, Sphere::class); + self::registerShape(self::CUBE, Cube::class); + self::registerShape(self::CUBOID, Cuboid::class); + self::registerShape(self::CYLINDER, Cylinder::class); + self::registerShape(self::CONE, Cone::class); + self::registerShape(self::PYRAMID, Pyramid::class); + self::registerShape(self::ELLIPSOID, Ellipsoid::class); + self::registerShape(self::CUSTOM, Custom::class); + } - public static function registerShape(string $name, string $class): void - { - self::$shapes[$name] = $class; - } + public static function registerShape(string $name, string $class): void + { + self::$shapes[$name] = $class; + } - /** - * @return array - */ - public static function getShapes(): array - { - return self::$shapes; - } + /** + * @return array + */ + public static function getShapes(): array + { + return self::$shapes; + } - /** - * @param string $name - * @return string - * @throws ShapeNotFoundException - */ - public static function getShape(string $name): string - { - if (isset(self::$shapes[$name])) return self::$shapes[$name]; - throw new ShapeNotFoundException("Shape $name not found"); - } + /** + * @param string $name + * @return string + * @throws ShapeNotFoundException + */ + public static function getShape(string $name): string + { + if (isset(self::$shapes[$name])) return self::$shapes[$name]; + throw new ShapeNotFoundException("Shape $name not found"); + } - /** - * @param string $shapeClass - * @return string - * @throws ShapeNotFoundException - */ - public static function getShapeName(string $shapeClass): string - { - $names = array_flip(self::$shapes); - if (isset($names[$shapeClass])) return $names[$shapeClass]; - throw new ShapeNotFoundException("Shape $shapeClass not found"); - } + /** + * @param string $shapeClass + * @return string + * @throws ShapeNotFoundException + */ + public static function getShapeName(string $shapeClass): string + { + $names = array_flip(self::$shapes); + if (isset($names[$shapeClass])) return $names[$shapeClass]; + throw new ShapeNotFoundException("Shape $shapeClass not found"); + } - public static function getDefaultShapeProperties(string $className): array - { - return array_diff_key(get_class_vars($className), get_class_vars(Shape::class)); - } + public static function getDefaultShapeProperties(string $className): array + { + return array_diff_key(get_class_vars($className), get_class_vars(Shape::class)); + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/session/PluginSession.php b/src/xenialdan/MagicWE2/session/PluginSession.php index ad6698ee..ad97b95a 100644 --- a/src/xenialdan/MagicWE2/session/PluginSession.php +++ b/src/xenialdan/MagicWE2/session/PluginSession.php @@ -23,25 +23,25 @@ public function __construct(Plugin $plugin) } public function getPlugin(): Plugin - { - return $this->plugin; - } - - public function __toString() - { - return __CLASS__ . - " UUID: " . $this->getUUID()->__toString() . - " Plugin: " . $this->getPlugin()->getName() . - " Selections: " . count($this->getSelections()) . - " Latest: " . $this->getLatestSelectionUUID() . - " Clipboards: " . count($this->getClipboards()) . - " Current: " . $this->getCurrentClipboardIndex() . - " Undos: " . count($this->undoHistory) . - " Redos: " . count($this->redoHistory); - } - - public function sendMessage(string $message): void - { - $this->plugin->getLogger()->info(Loader::PREFIX . $message); - } + { + return $this->plugin; + } + + public function __toString() + { + return __CLASS__ . + " UUID: " . $this->getUUID()->__toString() . + " Plugin: " . $this->getPlugin()->getName() . + " Selections: " . count($this->getSelections()) . + " Latest: " . $this->getLatestSelectionUUID() . + " Clipboards: " . count($this->getClipboards()) . + " Current: " . $this->getCurrentClipboardIndex() . + " Undos: " . count($this->undoHistory) . + " Redos: " . count($this->redoHistory); + } + + public function sendMessage(string $message): void + { + $this->plugin->getLogger()->info(Loader::PREFIX . $message); + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/session/Session.php b/src/xenialdan/MagicWE2/session/Session.php index 06ac0dfe..c3f6cf17 100644 --- a/src/xenialdan/MagicWE2/session/Session.php +++ b/src/xenialdan/MagicWE2/session/Session.php @@ -49,7 +49,7 @@ public function getUUID(): UUID } /** - * @param UUID $uuid + * @param UUID $uuid */ public function setUUID(UUID $uuid): void { @@ -103,203 +103,203 @@ public function &getLatestSelection(): ?Selection } /** - * @return Selection[] - */ - public function getSelections(): array - { - return $this->selections; - } + * @return Selection[] + */ + public function getSelections(): array + { + return $this->selections; + } - /** - * @param mixed $selections - */ - public function setSelections($selections): void - { - $this->selections = $selections; - } + /** + * @param mixed $selections + */ + public function setSelections($selections): void + { + $this->selections = $selections; + } - /** - * @return UUID|null - */ - public function getLatestSelectionUUID(): ?UUID - { - return $this->latestselection; - } + /** + * @return UUID|null + */ + public function getLatestSelectionUUID(): ?UUID + { + return $this->latestselection; + } - /** - * @param UUID $latestselection - */ - public function setLatestSelectionUUID(UUID $latestselection): void - { - $this->latestselection = $latestselection; - } + /** + * @param UUID $latestselection + */ + public function setLatestSelectionUUID(UUID $latestselection): void + { + $this->latestselection = $latestselection; + } - /** - * @return int - */ - public function getCurrentClipboardIndex(): int - { - return $this->currentClipboard; - } + /** + * @return int + */ + public function getCurrentClipboardIndex(): int + { + return $this->currentClipboard; + } - /** - * @return null|Clipboard - */ - public function getCurrentClipboard(): ?Clipboard - { - return $this->clipboards[$this->currentClipboard] ?? null; - } + /** + * @return null|Clipboard + */ + public function getCurrentClipboard(): ?Clipboard + { + return $this->clipboards[$this->currentClipboard] ?? null; + } - /** - * @param string $name - * @return null|Clipboard - */ - public function getClipboardByName(string $name): ?Clipboard - { - foreach ($this->clipboards as $clipboard) { - if ($clipboard->getCustomName() === $name) return $clipboard; - } - return null; - } + /** + * @param string $name + * @return null|Clipboard + */ + public function getClipboardByName(string $name): ?Clipboard + { + foreach ($this->clipboards as $clipboard) { + if ($clipboard->getCustomName() === $name) return $clipboard; + } + return null; + } - /** - * @param int $id - * @return null|Clipboard - */ - public function getClipboardById(int $id): ?Clipboard - { - return $this->clipboards[$id] ?? null; - } + /** + * @param int $id + * @return null|Clipboard + */ + public function getClipboardById(int $id): ?Clipboard + { + return $this->clipboards[$id] ?? null; + } - /** - * TODO - * @return Clipboard[] - */ - public function getClipboards(): array - { - return $this->clipboards; - } + /** + * TODO + * @return Clipboard[] + */ + public function getClipboards(): array + { + return $this->clipboards; + } - /** - * TODO - * @param Clipboard[] $clipboards - * @return bool - */ - public function setClipboards(array $clipboards): bool - { - $this->clipboards = $clipboards; - return true; - } + /** + * TODO + * @param Clipboard[] $clipboards + * @return bool + */ + public function setClipboards(array $clipboards): bool + { + $this->clipboards = $clipboards; + return true; + } - /** - * @param Clipboard $clipboard - * @param bool $setAsCurrent - * @return int The index of the clipboard - */ - public function addClipboard(Clipboard $clipboard, bool $setAsCurrent = true): int - { - $amount = array_push($this->clipboards, $clipboard); - if ($amount > self::MAX_CLIPBOARDS) array_shift($this->clipboards); - $i = array_search($clipboard, $this->clipboards, true); - if ($i !== false) { - if ($setAsCurrent) $this->currentClipboard = (int)$i; - return (int)$i; - } - return -1; - } + /** + * @param Clipboard $clipboard + * @param bool $setAsCurrent + * @return int The index of the clipboard + */ + public function addClipboard(Clipboard $clipboard, bool $setAsCurrent = true): int + { + $amount = array_push($this->clipboards, $clipboard); + if ($amount > self::MAX_CLIPBOARDS) array_shift($this->clipboards); + $i = array_search($clipboard, $this->clipboards, true); + if ($i !== false) { + if ($setAsCurrent) $this->currentClipboard = (int)$i; + return (int)$i; + } + return -1; + } - /** - * @param RevertClipboard $revertClipboard - */ - public function addRevert(RevertClipboard $revertClipboard): void - { - $this->redoHistory->clear(); - $this->undoHistory->push($revertClipboard); - while ($this->undoHistory->count() > self::MAX_HISTORY) { - $this->undoHistory->shift(); - } - } + /** + * @param RevertClipboard $revertClipboard + */ + public function addRevert(RevertClipboard $revertClipboard): void + { + $this->redoHistory->clear(); + $this->undoHistory->push($revertClipboard); + while ($this->undoHistory->count() > self::MAX_HISTORY) { + $this->undoHistory->shift(); + } + } - /** - * @throws Exception - */ - public function undo(): void - { - if ($this->undoHistory->count() === 0) { - $this->sendMessage(TF::RED . $this->getLanguage()->translateString('session.undo.none')); - return; - } - /** @var RevertClipboard $revertClipboard */ - $revertClipboard = $this->undoHistory->pop(); + /** + * @throws Exception + */ + public function undo(): void + { + if ($this->undoHistory->count() === 0) { + $this->sendMessage(TF::RED . $this->getLanguage()->translateString('session.undo.none')); + return; + } + /** @var RevertClipboard $revertClipboard */ + $revertClipboard = $this->undoHistory->pop(); $world = $revertClipboard->getWorld(); - foreach ($revertClipboard->chunks as $hash => $chunk) { + foreach ($revertClipboard->chunks as $hash => $chunk) { World::getXZ($hash, $x, $z); $revertClipboard->chunks[$hash] = $world->getChunk($x, $z); } - Server::getInstance()->getAsyncPool()->submitTask(new AsyncRevertTask($this->getUUID(), $revertClipboard, AsyncRevertTask::TYPE_UNDO)); - $this->sendMessage(TF::GREEN . $this->getLanguage()->translateString('session.undo.left', [count($this->undoHistory)])); - } + Server::getInstance()->getAsyncPool()->submitTask(new AsyncRevertTask($this->getUUID(), $revertClipboard, AsyncRevertTask::TYPE_UNDO)); + $this->sendMessage(TF::GREEN . $this->getLanguage()->translateString('session.undo.left', [count($this->undoHistory)])); + } - /** - * @throws InvalidArgumentException - * @throws RuntimeException - */ - public function redo(): void - { - if ($this->redoHistory->count() === 0) { - $this->sendMessage(TF::RED . $this->getLanguage()->translateString('session.redo.none')); - return; - } - /** @var RevertClipboard $revertClipboard */ - $revertClipboard = $this->redoHistory->pop(); - Server::getInstance()->getAsyncPool()->submitTask(new AsyncRevertTask($this->getUUID(), $revertClipboard, AsyncRevertTask::TYPE_REDO)); - $this->sendMessage(TF::GREEN . $this->getLanguage()->translateString('session.redo.left', [count($this->redoHistory)])); - } + /** + * @throws InvalidArgumentException + * @throws RuntimeException + */ + public function redo(): void + { + if ($this->redoHistory->count() === 0) { + $this->sendMessage(TF::RED . $this->getLanguage()->translateString('session.redo.none')); + return; + } + /** @var RevertClipboard $revertClipboard */ + $revertClipboard = $this->redoHistory->pop(); + Server::getInstance()->getAsyncPool()->submitTask(new AsyncRevertTask($this->getUUID(), $revertClipboard, AsyncRevertTask::TYPE_REDO)); + $this->sendMessage(TF::GREEN . $this->getLanguage()->translateString('session.redo.left', [count($this->redoHistory)])); + } - public function clearHistory(): void - { - $this->undoHistory->clear(); - $this->redoHistory->clear(); - } + public function clearHistory(): void + { + $this->undoHistory->clear(); + $this->redoHistory->clear(); + } - public function clearClipboard(): void - { - $this->setClipboards([]); - $this->currentClipboard = -1; - } + public function clearClipboard(): void + { + $this->setClipboards([]); + $this->currentClipboard = -1; + } - /** - * @return Language - */ - public function getLanguage(): Language - { - return Loader::getInstance()->getLanguage(); - } + /** + * @return Language + */ + public function getLanguage(): Language + { + return Loader::getInstance()->getLanguage(); + } abstract public function sendMessage(string $message): void; - public function __toString() - { - return __CLASS__ . - " UUID: " . $this->getUUID()->__toString() . - " Selections: " . count($this->getSelections()) . - " Latest: " . $this->getLatestSelectionUUID() . - " Clipboards: " . count($this->getClipboards()) . - " Current: " . $this->getCurrentClipboardIndex() . - " Undos: " . count($this->undoHistory) . - " Redos: " . count($this->redoHistory); - } + public function __toString() + { + return __CLASS__ . + " UUID: " . $this->getUUID()->__toString() . + " Selections: " . count($this->getSelections()) . + " Latest: " . $this->getLatestSelectionUUID() . + " Clipboards: " . count($this->getClipboards()) . + " Current: " . $this->getCurrentClipboardIndex() . + " Undos: " . count($this->undoHistory) . + " Redos: " . count($this->redoHistory); + } - /* - * TODO list: - * session storing/recovering from file/cleanup if too old - * session items - * recover session items + commands to get back already created/configured items/tool/brushes - * proper multi-selection-usage - * setState/getState on big actions, status bar/boss bar/texts/titles/popups - * inspect other player's sessions - * destroy session if owning player lost permission/gets banned - * optimise destroySession/__destruct of sessions - * clipboard selection (renaming?) - */ + /* + * TODO list: + * session storing/recovering from file/cleanup if too old + * session items + * recover session items + commands to get back already created/configured items/tool/brushes + * proper multi-selection-usage + * setState/getState on big actions, status bar/boss bar/texts/titles/popups + * inspect other player's sessions + * destroy session if owning player lost permission/gets banned + * optimise destroySession/__destruct of sessions + * clipboard selection (renaming?) + */ } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/session/UserSession.php b/src/xenialdan/MagicWE2/session/UserSession.php index 9960dfa1..f7990736 100644 --- a/src/xenialdan/MagicWE2/session/UserSession.php +++ b/src/xenialdan/MagicWE2/session/UserSession.php @@ -5,6 +5,7 @@ namespace xenialdan\MagicWE2\session; use Ds\Deque; +use Ds\Map; use Exception; use InvalidArgumentException; use jackmd\scorefactory\ScoreFactory; @@ -25,6 +26,8 @@ use xenialdan\MagicWE2\exception\ShapeNotFoundException; use xenialdan\MagicWE2\helper\Scoreboard; use xenialdan\MagicWE2\Loader; +use xenialdan\MagicWE2\session\data\Asset; +use xenialdan\MagicWE2\session\data\BrushStore; use xenialdan\MagicWE2\tool\Brush; use xenialdan\MagicWE2\tool\BrushProperties; @@ -44,8 +47,10 @@ class UserSession extends Session implements JsonSerializable //TODO use JsonMap private $wailaEnabled = true; /** @var bool */ private $sidebarEnabled = true;//TODO settings/commands - /** @var Brush[] */ - private $brushes = []; + /** @var Map */ + private Map $brushes; + /** @var Map */ + private Map $assets; /** @var Language|null */ private $lang; @@ -61,6 +66,8 @@ public function __construct(Player $player) } $this->undoHistory = new Deque(); $this->redoHistory = new Deque(); + $this->brushes = new Map(); + $this->assets = new Map(); try { if (is_null($this->lang)) $this->lang = new Language(Language::FALLBACK_LANGUAGE, Loader::getInstance()->getLanguageFolder()); @@ -308,7 +315,7 @@ public function replaceBrush(Brush $brush): void */ public function getBrushes(): array { - return $this->brushes; + return $this->brushes->values()->toArray(); } public function cleanupInventory(): void diff --git a/src/xenialdan/MagicWE2/session/data/Asset.php b/src/xenialdan/MagicWE2/session/data/Asset.php new file mode 100644 index 00000000..a0642aba --- /dev/null +++ b/src/xenialdan/MagicWE2/session/data/Asset.php @@ -0,0 +1,129 @@ +filename = $filename; + $this->displayname = pathinfo($filename, PATHINFO_FILENAME); + $this->structure = $value; + $this->locked = $locked; + $this->ownerXuid = $ownerXuid; + } + + public function getSize(): Vector3 + { + if ($this->structure instanceof Schematic) return new Vector3($this->structure->getWidth(), $this->structure->getHeight(), $this->structure->getLength()); + if ($this->structure instanceof MCStructure) return $this->structure->getSize(); + if ($this->structure instanceof SingleClipboard) return new Vector3($this->structure->selection->getSizeX(), $this->structure->selection->getSizeY(), $this->structure->selection->getSizeZ()); + throw new UnexpectedValueException('Invalid class as Asset'); + } + + public function getTotalCount(): int + { + if ($this->structure instanceof Schematic || $this->structure instanceof MCStructure) return $this->getSize()->getFloorX() * $this->getSize()->getFloorY() * $this->getSize()->getFloorZ(); + if ($this->structure instanceof SingleClipboard) return $this->structure->getTotalCount(); + throw new UnexpectedValueException('Invalid class as Asset'); + } + + public function getOrigin(): Vector3 + { + if ($this->structure instanceof Schematic) return new Vector3(0, 0, 0); + if ($this->structure instanceof MCStructure) return $this->structure->getStructureWorldOrigin(); + if ($this->structure instanceof SingleClipboard) return $this->structure->position; + throw new UnexpectedValueException('Invalid class as Asset'); + } + + /** + * @param bool $renew + * @return Item + * @throws InvalidArgumentException + * @throws TypeError + */ + public function toItem(bool $renew = false): Item + { + if ($this->item !== null && !$renew) return $this->item; + $item = ItemFactory::getInstance()->get(ItemIds::SCAFFOLDING); + $item->addEnchantment(new EnchantmentInstance(Loader::$ench)); + [$filename, $displayname, $type, $locked, $owner] = $this->jsonSerialize(); + $item->getNamedTag()->setTag(API::TAG_MAGIC_WE_ASSET, + CompoundTag::create() + ->setString("filename", $filename) + ->setString("displayname", $displayname) + ->setString("type", $type) + ->setByte("locked", $locked ? 1 : 0) + ->setString("owner", $owner) + ); + $item->setCustomName(Loader::PREFIX . TF::BOLD . TF::DARK_PURPLE . $displayname); + $item->setLore($this->generateLore()); + $this->item = $item; + return $item; + } + + /** + * @return array + */ + private function generateLore(): array + { + $return = []; + foreach ($this->jsonSerialize() as $k => $v) { + if ($v === '' || $v === 'displayname') continue; + if (is_bool($v)) { + $return[] = (ucfirst($k) . ": " . ($v ? "Yes" : "No")); + continue; + } + $return[] = (ucfirst($k) . ": " . $v); + } + return $return; + } + + public function jsonSerialize() + { + return [ + 'filename' => $this->filename, + 'displayname' => $this->displayname, + 'type' => $this->structure instanceof Schematic ? self::TYPE_SCHEMATIC : ($this->structure instanceof MCStructure ? self::TYPE_MCSTRUCTURE : ($this->structure instanceof SingleClipboard ? self::TYPE_CLIPBOARD : '')), + 'locked' => $this->locked, + 'owner' => $this->ownerXuid ?? '', + ]; + } +} \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/session/data/AssetCollection.php b/src/xenialdan/MagicWE2/session/data/AssetCollection.php new file mode 100644 index 00000000..47bb1aae --- /dev/null +++ b/src/xenialdan/MagicWE2/session/data/AssetCollection.php @@ -0,0 +1,72 @@ + */ + public Map $assets; + + public function __construct() + { + $this->assets = new Map(); + $this->initFolders(); + } + + /** @return Asset[] */ + public function getAssets(): array + { + return $this->assets->values()->toArray(); + } + + /** @return Asset[] */ + public function getAssetsGlobal(): array + { + return $this->assets->filter(function (string $key, Asset $value) { + return $value->ownerXuid !== ''; + })->values()->toArray(); + } + + /** + * @param string|null $xuid + * @return Asset[] + */ + public function getPlayerAssets(?string $xuid = null): array + { + return $this->assets->filter(function (string $key, Asset $value) use ($xuid) { + return $value->ownerXuid === $xuid; + })->values()->toArray(); + } + + private function initFolders() + { + //Load mcstructure and schematic files and lock them to prevent editing + $store = $this; + $schematicFiles = array_merge(glob(Loader::getInstance()->getDataFolder() . 'assets' . DIRECTORY_SEPARATOR . "*.mcstructure"), glob(Loader::getInstance()->getDataFolder() . 'assets' . DIRECTORY_SEPARATOR . "*.schematic"));//glob might return false + if ($schematicFiles !== false) + foreach ($schematicFiles as $file) { + ['basename' => $basename, 'extension' => $extension] = pathinfo($file); + Loader::getInstance()->getLogger()->debug(TF::GOLD . "Loading " . $basename); + try { + if ($extension === 'mcstructure') { + $store->assets->put($basename, new Asset($basename, StructureStore::getInstance()->loadStructure($basename), true)); + } else if ($extension === 'schematic') { + $store->assets->put($basename, new Asset($basename, StructureStore::getInstance()->loadSchematic($basename), true)); + } + } catch (StructureFileException $e) { + Loader::getInstance()->getLogger()->debug($e->getMessage()); + } + } + } +} \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/session/data/TODO.md b/src/xenialdan/MagicWE2/session/data/TODO.md new file mode 100644 index 00000000..9143b8a6 --- /dev/null +++ b/src/xenialdan/MagicWE2/session/data/TODO.md @@ -0,0 +1,5 @@ +# Session data serialization +- [] Brushes +- [x] Assets (session + global) +- [] Palettes +- [] Clipboards \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/AsyncActionTask.php b/src/xenialdan/MagicWE2/task/AsyncActionTask.php index 9ac49b94..38241469 100644 --- a/src/xenialdan/MagicWE2/task/AsyncActionTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncActionTask.php @@ -27,13 +27,13 @@ class AsyncActionTask extends MWEAsyncTask { - /* - * Intention: - * Shape: get blocks from a shape. Shape can contain options - * Filterblocks: filter out blocks that are not needed - * Action: action to run on the remaining blocks, return previous blocks - * Strings: Begin, completion, bossbar, other stuff can be in the action - */ + /* + * Intention: + * Shape: get blocks from a shape. Shape can contain options + * Filterblocks: filter out blocks that are not needed + * Action: action to run on the remaining blocks, return previous blocks + * Strings: Begin, completion, bossbar, other stuff can be in the action + */ /** @var string */ private $touchedChunks; @@ -66,25 +66,25 @@ public function __construct(UUID $sessionUUID, Selection $selection, TaskAction $this->blockFilter = $blockFilter; try { - $session = SessionHelper::getSessionByUUID($sessionUUID); - if ($session instanceof UserSession) { - $player = $session->getPlayer(); - /** @var Player $player */ - $session->getBossBar()->showTo([$player]); - $session->getBossBar()->setTitle("Running {$action::getName()} action");//TODO better string - } - } catch (SessionException $e) { - Loader::getInstance()->getLogger()->logException($e); - } - } + $session = SessionHelper::getSessionByUUID($sessionUUID); + if ($session instanceof UserSession) { + $player = $session->getPlayer(); + /** @var Player $player */ + $session->getBossBar()->showTo([$player]); + $session->getBossBar()->setTitle("Running {$action::getName()} action");//TODO better string + } + } catch (SessionException $e) { + Loader::getInstance()->getLogger()->logException($e); + } + } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress(new Progress(0, "Preparing {$this->action::getName()}")); @@ -162,6 +162,6 @@ public function onCompletion(): void $session->addRevert(new RevertClipboard($selection->worldId, $undoChunks, self::multipleBlocksToData($oldBlocksBlocks))); if ($this->action->addClipboard) $session->addClipboard($oldBlocks); - } - } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/AsyncClipboardActionTask.php b/src/xenialdan/MagicWE2/task/AsyncClipboardActionTask.php index 2e10b805..2481a4cc 100644 --- a/src/xenialdan/MagicWE2/task/AsyncClipboardActionTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncClipboardActionTask.php @@ -58,17 +58,17 @@ public function __construct(UUID $sessionUUID, Selection $selection, ClipboardAc $session->getBossBar()->setTitle("Running {$action::getName()} clipboard action");//TODO better string } } catch (SessionException $e) { - Loader::getInstance()->getLogger()->logException($e); - } - } + Loader::getInstance()->getLogger()->logException($e); + } + } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress(new Progress(0, "Preparing {$this->action::getName()}")); BlockStatesParser::$doorRotPath = $this->doorRotPath; diff --git a/src/xenialdan/MagicWE2/task/AsyncCopyTask.php b/src/xenialdan/MagicWE2/task/AsyncCopyTask.php index 7b2f8c97..350040da 100644 --- a/src/xenialdan/MagicWE2/task/AsyncCopyTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncCopyTask.php @@ -42,23 +42,23 @@ class AsyncCopyTask extends MWEAsyncTask * @param int $flags * @throws Exception */ - public function __construct(UUID $sessionUUID, Selection $selection, Vector3 $offset, array $chunks, int $flags) - { - $this->start = microtime(true); - $this->chunks = serialize($chunks); - $this->sessionUUID = $sessionUUID->toString(); - $this->selection = serialize($selection); - $this->offset = $offset->asVector3()->floor(); - $this->flags = $flags; - } + public function __construct(UUID $sessionUUID, Selection $selection, Vector3 $offset, array $chunks, int $flags) + { + $this->start = microtime(true); + $this->chunks = serialize($chunks); + $this->sessionUUID = $sessionUUID->toString(); + $this->selection = serialize($selection); + $this->offset = $offset->asVector3()->floor(); + $this->flags = $flags; + } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress([0, "Start"]); $chunks = array_map(static function ($chunk) { @@ -76,17 +76,17 @@ public function onRun(): void $totalCount = $selection->getShape()->getTotalCount(); $copied = $this->copyBlocks($selection, $manager, $clipboard); #$clipboard->setShape($selection->getShape()); - #$clipboard->chunks = $manager->getChunks(); - $this->setResult(compact("clipboard", "copied", "totalCount")); - } + #$clipboard->chunks = $manager->getChunks(); + $this->setResult(compact("clipboard", "copied", "totalCount")); + } - /** - * @param Selection $selection - * @param AsyncChunkManager $manager - * @param SingleClipboard $clipboard - * @return int - * @throws Exception - */ + /** + * @param Selection $selection + * @param AsyncChunkManager $manager + * @param SingleClipboard $clipboard + * @return int + * @throws Exception + */ private function copyBlocks(Selection $selection, AsyncChunkManager $manager, SingleClipboard $clipboard): int { $blockCount = $selection->getShape()->getTotalCount(); @@ -107,10 +107,10 @@ private function copyBlocks(Selection $selection, AsyncChunkManager $manager, Si $lastprogress = $progress; } } - return $i; - } + return $i; + } - public function onCompletion(): void + public function onCompletion(): void { try { $session = SessionHelper::getSessionByUUID(UUID::fromString($this->sessionUUID)); diff --git a/src/xenialdan/MagicWE2/task/AsyncCountTask.php b/src/xenialdan/MagicWE2/task/AsyncCountTask.php index c5ffbf3e..13cd8c8d 100644 --- a/src/xenialdan/MagicWE2/task/AsyncCountTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncCountTask.php @@ -49,13 +49,13 @@ public function __construct(UUID $sessionUUID, Selection $selection, array $touc $this->flags = $flags; } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress([0, "Start"]); $chunks = unserialize($this->touchedChunks/*, ['allowed_classes' => [false]]*/);//TODO test pm4 @@ -133,7 +133,7 @@ public function onCompletion(): void $session->sendMessage(TF::AQUA . $count . "x | " . round($count / $totalCount * 100) . "% | " . $block); } } catch (SessionException $e) { - Loader::getInstance()->getLogger()->logException($e); - } - } + Loader::getInstance()->getLogger()->logException($e); + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/AsyncReplaceTask.php b/src/xenialdan/MagicWE2/task/AsyncReplaceTask.php index 40f747a9..8bb780ab 100644 --- a/src/xenialdan/MagicWE2/task/AsyncReplaceTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncReplaceTask.php @@ -58,13 +58,13 @@ public function __construct(UUID $sessionUUID, Selection $selection, array $touc $this->flags = $flags; } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress([0, "Start"]); diff --git a/src/xenialdan/MagicWE2/task/AsyncRevertTask.php b/src/xenialdan/MagicWE2/task/AsyncRevertTask.php index 399083ea..d98b1a58 100644 --- a/src/xenialdan/MagicWE2/task/AsyncRevertTask.php +++ b/src/xenialdan/MagicWE2/task/AsyncRevertTask.php @@ -36,18 +36,18 @@ class AsyncRevertTask extends MWEAsyncTask public function __construct(UUID $sessionUUID, RevertClipboard $clipboard, $type = self::TYPE_UNDO) { $this->sessionUUID = $sessionUUID->toString(); - $this->start = microtime(true); - $this->clipboard = serialize($clipboard); - $this->type = $type; - } + $this->start = microtime(true); + $this->clipboard = serialize($clipboard); + $this->type = $type; + } - /** - * Actions to execute when run - * - * @return void - * @throws Exception - */ - public function onRun(): void + /** + * Actions to execute when run + * + * @return void + * @throws Exception + */ + public function onRun(): void { $this->publishProgress([0, "Start"]); /** @var RevertClipboard $clipboard */ @@ -142,12 +142,12 @@ public function onCompletion(): void break; } case self::TYPE_REDO: - { - $session->sendMessage(TF::GREEN . $session->getLanguage()->translateString('task.revert.redo.success', [$this->generateTookString(), $changed, $totalCount])); - $session->undoHistory->push($clipboard); - break; - } - } - } - } + { + $session->sendMessage(TF::GREEN . $session->getLanguage()->translateString('task.revert.redo.success', [$this->generateTookString(), $changed, $totalCount])); + $session->undoHistory->push($clipboard); + break; + } + } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/ActionRegistry.php b/src/xenialdan/MagicWE2/task/action/ActionRegistry.php index 62c503f5..0376b361 100644 --- a/src/xenialdan/MagicWE2/task/action/ActionRegistry.php +++ b/src/xenialdan/MagicWE2/task/action/ActionRegistry.php @@ -20,44 +20,44 @@ public function __construct() } public static function registerAction(string $name, string $class): void - { - self::$actions[$name] = $class; - } - - /** - * @return array - */ - public static function getActions(): array - { - return self::$actions; - } - - /** - * @param string $name - * @return string - * @throws ActionNotFoundException - */ - public static function getAction(string $name): string - { - if (isset(self::$actions[$name])) return self::$actions[$name]; - throw new ActionNotFoundException("Action $name not found"); - } - - /** - * @param string $actionClass - * @return string - * @throws ActionNotFoundException - */ - public static function getActionName(string $actionClass): string - { - $names = array_flip(self::$actions); - if (isset($names[$actionClass])) return $names[$actionClass]; - throw new ActionNotFoundException("Action $actionClass not found"); - } - - public static function getDefaultActionProperties(string $className): array - { - return array_diff_key(get_class_vars($className), get_class_vars(TaskAction::class)); - } + { + self::$actions[$name] = $class; + } + + /** + * @return array + */ + public static function getActions(): array + { + return self::$actions; + } + + /** + * @param string $name + * @return string + * @throws ActionNotFoundException + */ + public static function getAction(string $name): string + { + if (isset(self::$actions[$name])) return self::$actions[$name]; + throw new ActionNotFoundException("Action $name not found"); + } + + /** + * @param string $actionClass + * @return string + * @throws ActionNotFoundException + */ + public static function getActionName(string $actionClass): string + { + $names = array_flip(self::$actions); + if (isset($names[$actionClass])) return $names[$actionClass]; + throw new ActionNotFoundException("Action $actionClass not found"); + } + + public static function getDefaultActionProperties(string $className): array + { + return array_diff_key(get_class_vars($className), get_class_vars(TaskAction::class)); + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/CountAction.php b/src/xenialdan/MagicWE2/task/action/CountAction.php index 206a5ca2..ec841ec8 100644 --- a/src/xenialdan/MagicWE2/task/action/CountAction.php +++ b/src/xenialdan/MagicWE2/task/action/CountAction.php @@ -60,15 +60,15 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { yield $progress; $lastProgress = $progress; - } - } - $messages[] = TF::DARK_AQUA . count($counts) . " blocks found in a total of $count blocks"; - uasort($counts, static function ($a, $b) { + } + } + $messages[] = TF::DARK_AQUA . count($counts) . " blocks found in a total of $count blocks"; + uasort($counts, static function ($a, $b) { if ($a === $b) return 0; return ($a > $b) ? -1 : 1; }); - foreach ($counts as $block => $countb) { - $messages[] = TF::AQUA . $countb . "x | " . round($countb / $count * 100) . "% | " . $block; - } - } + foreach ($counts as $block => $countb) { + $messages[] = TF::AQUA . $countb . "x | " . round($countb / $count * 100) . "% | " . $block; + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/CutAction.php b/src/xenialdan/MagicWE2/task/action/CutAction.php index 2de6fd56..a32b0d86 100644 --- a/src/xenialdan/MagicWE2/task/action/CutAction.php +++ b/src/xenialdan/MagicWE2/task/action/CutAction.php @@ -68,7 +68,7 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { yield $progress; $lastProgress = $progress; - } - } - } + } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/FlipAction.php b/src/xenialdan/MagicWE2/task/action/FlipAction.php index d2ca8187..cd08b739 100644 --- a/src/xenialdan/MagicWE2/task/action/FlipAction.php +++ b/src/xenialdan/MagicWE2/task/action/FlipAction.php @@ -38,16 +38,16 @@ public static function getName(): string return "Flip"; } - /** - * @param string $sessionUUID - * @param Selection $selection - * @param null|int $changed - * @param SingleClipboard $clipboard - * @param string[] $messages - * @return Generator|Progress[] - * @throws Exception - */ - public function execute(string $sessionUUID, Selection $selection, ?int &$changed, SingleClipboard $clipboard, array &$messages = []): Generator + /** + * @param string $sessionUUID + * @param Selection $selection + * @param null|int $changed + * @param SingleClipboard $clipboard + * @param string[] $messages + * @return Generator|Progress[] + * @throws Exception + */ + public function execute(string $sessionUUID, Selection $selection, ?int &$changed, SingleClipboard $clipboard, array &$messages = []): Generator { //TODO modify position. For now, just flip the blocks around their own axis $changed = 0; @@ -58,34 +58,34 @@ public function execute(string $sessionUUID, Selection $selection, ?int &$change $clonedClipboard = clone $clipboard; $x = $y = $z = null; $maxX = $clipboard->selection->getSizeX() - 1; - $maxY = $clipboard->selection->getSizeY() - 1; - $maxZ = $clipboard->selection->getSizeZ() - 1; - foreach ($clipboard->iterateEntries($x, $y, $z) as $blockEntry) { - #var_dump("$x $y $z"); - if ($this->axis === self::AXIS_Z || $this->axis === self::AXIS_XZ) - $x = $maxX - $x; - if ($this->axis === self::AXIS_X || $this->axis === self::AXIS_XZ) - $z = $maxZ - $z; - if ($this->axis === self::AXIS_Y) - $y = $maxY - $y; - #var_dump("$x $y $z"); + $maxY = $clipboard->selection->getSizeY() - 1; + $maxZ = $clipboard->selection->getSizeZ() - 1; + foreach ($clipboard->iterateEntries($x, $y, $z) as $blockEntry) { + #var_dump("$x $y $z"); + if ($this->axis === self::AXIS_Z || $this->axis === self::AXIS_XZ) + $x = $maxX - $x; + if ($this->axis === self::AXIS_X || $this->axis === self::AXIS_XZ) + $z = $maxZ - $z; + if ($this->axis === self::AXIS_Y) + $y = $maxY - $y; + #var_dump("$x $y $z"); $block1 = $blockEntry->toBlock(); $blockStatesEntry = BlockStatesParser::getInstance()::getStateByBlock($block1); $mirrored = $blockStatesEntry->mirror($this->axis); - $block = $mirrored->toBlock(); - $entry = BlockEntry::fromBlock($block); + $block = $mirrored->toBlock(); + $entry = BlockEntry::fromBlock($block); //var_dump($blockStatesEntry->__toString(), $mirrored->__toString(), $block); - /** @var int $x */ - /** @var int $y */ - /** @var int $z */ - $clonedClipboard->addEntry($x, $y, $z, $entry); - $changed++; - $progress = new Progress($changed / $count, "$changed/$count"); - if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { - yield $progress; - $lastProgress = $progress; - } - } - $clipboard = $clonedClipboard; - } + /** @var int $x */ + /** @var int $y */ + /** @var int $z */ + $clonedClipboard->addEntry($x, $y, $z, $entry); + $changed++; + $progress = new Progress($changed / $count, "$changed/$count"); + if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { + yield $progress; + $lastProgress = $progress; + } + } + $clipboard = $clonedClipboard; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/RotateAction.php b/src/xenialdan/MagicWE2/task/action/RotateAction.php index 510a9075..5dd52b09 100644 --- a/src/xenialdan/MagicWE2/task/action/RotateAction.php +++ b/src/xenialdan/MagicWE2/task/action/RotateAction.php @@ -39,8 +39,8 @@ public function __construct(int $rotation, bool $aroundOrigin = true) public static function getName(): string { - return "Rotate"; - } + return "Rotate"; + } /** * @param string $sessionUUID diff --git a/src/xenialdan/MagicWE2/task/action/SetBiomeAction.php b/src/xenialdan/MagicWE2/task/action/SetBiomeAction.php index afaf53bc..678194a3 100644 --- a/src/xenialdan/MagicWE2/task/action/SetBiomeAction.php +++ b/src/xenialdan/MagicWE2/task/action/SetBiomeAction.php @@ -52,10 +52,10 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan $manager->getChunk($vec2->x >> 4, $vec2->y >> 4)->setBiomeId($vec2->x % 16, $vec2->y % 16, $this->biomeId); $changed++; $progress = new Progress($changed / $count, "Changed Biome for $changed/$count blocks"); - if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { - yield $progress; - $lastProgress = $progress; - } - } - } + if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { + yield $progress; + $lastProgress = $progress; + } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/SetBlockAction.php b/src/xenialdan/MagicWE2/task/action/SetBlockAction.php index 3413e7bb..f1375769 100644 --- a/src/xenialdan/MagicWE2/task/action/SetBlockAction.php +++ b/src/xenialdan/MagicWE2/task/action/SetBlockAction.php @@ -17,14 +17,14 @@ class SetBlockAction extends TaskAction { - public function __construct() - { - } + public function __construct() + { + } - public static function getName(): string - { - return "Set block"; - } + public static function getName(): string + { + return "Set block"; + } /** * @param string $sessionUUID @@ -58,9 +58,9 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan $i++; $progress = new Progress($i / $count, "Changed {$changed} blocks out of {$count}"); if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) { - yield $progress; - $lastProgress = $progress; - } - } - } + yield $progress; + $lastProgress = $progress; + } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/TaskAction.php b/src/xenialdan/MagicWE2/task/action/TaskAction.php index 08571715..d99e25ca 100644 --- a/src/xenialdan/MagicWE2/task/action/TaskAction.php +++ b/src/xenialdan/MagicWE2/task/action/TaskAction.php @@ -50,5 +50,5 @@ public function setClipboardVector(?Vector3 $clipboardVector): void { if ($clipboardVector instanceof Vector3) $clipboardVector = $clipboardVector->asVector3()->floor(); $this->clipboardVector = $clipboardVector; - } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/task/action/ThawAction.php b/src/xenialdan/MagicWE2/task/action/ThawAction.php index fdb5d81c..6ac2559b 100644 --- a/src/xenialdan/MagicWE2/task/action/ThawAction.php +++ b/src/xenialdan/MagicWE2/task/action/ThawAction.php @@ -17,14 +17,14 @@ class ThawAction extends TaskAction { - public function __construct() - { - } + public function __construct() + { + } - public static function getName(): string - { - return "Thaw"; - } + public static function getName(): string + { + return "Thaw"; + } /** * @param string $sessionUUID @@ -64,6 +64,6 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan $lastProgress = $progress; } } - } - } + } + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/tool/Brush.php b/src/xenialdan/MagicWE2/tool/Brush.php index ef9d2cc6..8c84a5c5 100644 --- a/src/xenialdan/MagicWE2/tool/Brush.php +++ b/src/xenialdan/MagicWE2/tool/Brush.php @@ -8,11 +8,9 @@ use InvalidArgumentException; use JsonException; use pocketmine\data\bedrock\BiomeIds; -use pocketmine\item\Durable; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\VanillaItems; use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\utils\AssumptionFailedError; @@ -69,8 +67,7 @@ public function getName(): string */ public function toItem(): Item { - /** @var Durable $item */ - $item = ItemFactory::getInstance()->get(ItemIds::WOODEN_SHOVEL); + $item = VanillaItems::WOODEN_SHOVEL(); $item->addEnchantment(new EnchantmentInstance(Loader::$ench)); $uuid = $this->properties->uuid ?? UUID::fromRandom()->toString(); $this->properties->uuid = $uuid; @@ -109,16 +106,16 @@ public function getForm(bool $new = true, array $errors = []): CustomForm $dropdownShape = new Dropdown((isset($errors['shape']) ? TF::RED : "") . "Shape" . ($errors['shape'] ?? "")); foreach (Loader::getShapeRegistry()::getShapes() as $name => $class) { if ($name === ShapeRegistry::CUSTOM) continue; - $dropdownShape->addOption($name, $class === $brushProperties->shape); - } - $form->addElement($dropdownShape); - } else { - $form->addElement(new Label($brushProperties->getShapeName())); - } - // Action - $dropdownAction = new Dropdown("Action"); - foreach (ActionRegistry::getActions() as $name => $class) { - $dropdownAction->addOption($name, $class === $brushProperties->action); + $dropdownShape->addOption($name, $class === $brushProperties->shape); + } + $form->addElement($dropdownShape); + } else { + $form->addElement(new Label($brushProperties->getShapeName())); + } + // Action + $dropdownAction = new Dropdown("Action"); + foreach (ActionRegistry::getActions() as $name => $class) { + $dropdownAction->addOption($name, $class === $brushProperties->action); } $form->addElement($dropdownAction); // Name @@ -142,14 +139,14 @@ public function getForm(bool $new = true, array $errors = []): CustomForm $form->addElement($element); } } - // Function - $form->setCallable(function (Player $player, $data) use ($form, $new) { - #var_dump(__LINE__, $data); - #$data = array_slice($data, 0, 7); - [$shape, $action, $name, $blocks, $filter, $biome, $hollow] = $data; - $extraData = []; - #var_dump(__LINE__, array_slice($data, 7)); - $base = ShapeRegistry::getDefaultShapeProperties(ShapeRegistry::getShape($shape)); + // Function + $form->setCallable(function (Player $player, $data) use ($form, $new) { + #var_dump(__LINE__, $data); + #$data = array_slice($data, 0, 7); + [$shape, $action, $name, $blocks, $filter, $biome, $hollow] = $data; + $extraData = []; + #var_dump(__LINE__, array_slice($data, 7)); + $base = ShapeRegistry::getDefaultShapeProperties(ShapeRegistry::getShape($shape)); foreach (array_slice($data, 7, null, true) as $i => $value) { #var_dump($i, $value, gettype($value), gettype($base[lcfirst($form->getElement($i)->getText())])); if (is_int($base[lcfirst($form->getElement($i)->getText())])) $value = (int)$value; @@ -174,104 +171,104 @@ public function getForm(bool $new = true, array $errors = []): CustomForm $p = BlockPalette::fromString($blocks); if ($p->empty()) throw new AssumptionFailedError("Blocks cannot be empty!"); } catch (Exception $ex) { - $error['blocks'] = $ex->getMessage(); - } - try { + $error['blocks'] = $ex->getMessage(); + } + try { BlockPalette::fromString($filter); } catch (Exception $ex) { - $error['filter'] = $ex->getMessage(); - } - try { - $shape = Loader::getShapeRegistry()::getShape($shape); - } catch (Exception $ex) { - $error['shape'] = $ex->getMessage(); - } - try { - $action = Loader::getActionRegistry()::getAction($action); - } catch (Exception $ex) { - $error['action'] = $ex->getMessage(); - } - try { + $error['filter'] = $ex->getMessage(); + } + try { + $shape = Loader::getShapeRegistry()::getShape($shape); + } catch (Exception $ex) { + $error['shape'] = $ex->getMessage(); + } + try { + $action = Loader::getActionRegistry()::getAction($action); + } catch (Exception $ex) { + $error['action'] = $ex->getMessage(); + } + try { if (!is_int($biomeId)) throw new AssumptionFailedError("Biome not found"); - } catch (Exception $ex) { - $error['biome'] = $ex->getMessage(); - } + } catch (Exception $ex) { + $error['biome'] = $ex->getMessage(); + } - //Set properties (called before resending, so form contains errors) - if (!empty(trim(TF::clean($name)))) $this->properties->customName = $name; - if (!isset($error['shape'])) { - $this->properties->shape = $shape; - if (!$new && !empty($extraData)) - $this->properties->shapeProperties = $extraData; - } - if (!isset($error['action'])) $this->properties->action = $action; - /*if (!isset($error['blocks']))*/ - $this->properties->blocks = $blocks; - /*if (!isset($error['filter']))*/ - $this->properties->filter = $filter; - $this->properties->hollow = $hollow; + //Set properties (called before resending, so form contains errors) + if (!empty(trim(TF::clean($name)))) $this->properties->customName = $name; + if (!isset($error['shape'])) { + $this->properties->shape = $shape; + if (!$new && !empty($extraData)) + $this->properties->shapeProperties = $extraData; + } + if (!isset($error['action'])) $this->properties->action = $action; + /*if (!isset($error['blocks']))*/ + $this->properties->blocks = $blocks; + /*if (!isset($error['filter']))*/ + $this->properties->filter = $filter; + $this->properties->hollow = $hollow; - //Resend form upon error - if (!empty($error)) { - $player->sendForm($this->getForm($new, $error)); - return; - } + //Resend form upon error + if (!empty($error)) { + $player->sendForm($this->getForm($new, $error)); + return; + } - //Debug - #print_r($extraData); - try { - $brush = $this; - $session = SessionHelper::getUserSession($player); - if (!$session instanceof UserSession) { + //Debug + #print_r($extraData); + try { + $brush = $this; + $session = SessionHelper::getUserSession($player); + if (!$session instanceof UserSession) { throw new SessionException(Loader::getInstance()->getLanguage()->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - if (!$new) { - $session->replaceBrush($brush); - } else { - $player->sendForm($this->getExtradataForm($this->properties->shape)); - } - } catch (Exception $ex) { - $player->sendMessage($ex->getMessage()); - Loader::getInstance()->getLogger()->logException($ex); - } - }); - return $form; - } catch (Exception $e) { + } + if (!$new) { + $session->replaceBrush($brush); + } else { + $player->sendForm($this->getExtradataForm($this->properties->shape)); + } + } catch (Exception $ex) { + $player->sendMessage($ex->getMessage()); + Loader::getInstance()->getLogger()->logException($ex); + } + }); + return $form; + } catch (Exception $e) { throw new AssumptionFailedError("Could not create brush form"); - } - } + } + } - private function getExtradataForm(string $shapeClass): CustomForm - { - $form = new CustomForm("Shape settings"); - #foreach (($defaultReplaced = array_merge(ShapeRegistry::getDefaultShapeProperties($shapeClass), $this->properties->shapeProperties)) as $name => $value) { - $base = ShapeRegistry::getDefaultShapeProperties($shapeClass); - foreach (($defaultReplaced = array_replace($base, array_intersect_key($this->properties->shapeProperties, $base))) as $name => $value) { + private function getExtradataForm(string $shapeClass): CustomForm + { + $form = new CustomForm("Shape settings"); + #foreach (($defaultReplaced = array_merge(ShapeRegistry::getDefaultShapeProperties($shapeClass), $this->properties->shapeProperties)) as $name => $value) { + $base = ShapeRegistry::getDefaultShapeProperties($shapeClass); + foreach (($defaultReplaced = array_replace($base, array_intersect_key($this->properties->shapeProperties, $base))) as $name => $value) { if (is_bool($value)) $form->addElement(new Toggle(ucfirst($name), $value)); else $form->addElement(new Input(ucfirst($name), $name . " (" . gettype($value) . ")", (string)$value)); } - #var_dump($this->properties->shapeProperties); - #var_dump('Base', $base); - #var_dump('Default Replaced', $defaultReplaced); - $form->setCallable(function (Player $player, $data) use ($defaultReplaced, $base) { - //TODO validation, resending etc. - $extraData = []; - $names = array_keys($defaultReplaced); - foreach ($data as $index => $value) { + #var_dump($this->properties->shapeProperties); + #var_dump('Base', $base); + #var_dump('Default Replaced', $defaultReplaced); + $form->setCallable(function (Player $player, $data) use ($defaultReplaced, $base) { + //TODO validation, resending etc. + $extraData = []; + $names = array_keys($defaultReplaced); + foreach ($data as $index => $value) { if (is_int($base[$names[$index]])) $value = (int)$value; - $extraData[$names[$index]] = $value; - } - $this->properties->shapeProperties = $extraData; + $extraData[$names[$index]] = $value; + } + $this->properties->shapeProperties = $extraData; - $brush = $this; - $session = SessionHelper::getUserSession($player); - if (!$session instanceof UserSession) { + $brush = $this; + $session = SessionHelper::getUserSession($player); + if (!$session instanceof UserSession) { throw new SessionException(Loader::getInstance()->getLanguage()->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $this->properties->uuid = UUID::fromRandom()->toString(); - $session->addBrush($brush); - $player->getInventory()->addItem($brush->toItem()); - }); - return $form; - } + } + $this->properties->uuid = UUID::fromRandom()->toString(); + $session->addBrush($brush); + $player->getInventory()->addItem($brush->toItem()); + }); + return $form; + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/tool/BrushProperties.php b/src/xenialdan/MagicWE2/tool/BrushProperties.php index 7b86e50d..c19f9594 100644 --- a/src/xenialdan/MagicWE2/tool/BrushProperties.php +++ b/src/xenialdan/MagicWE2/tool/BrushProperties.php @@ -53,98 +53,98 @@ class BrushProperties implements JsonSerializable */ public function jsonSerialize() { - return (array)$this; - } + return (array)$this; + } - /** - * @param array $json - * @return BrushProperties - * @throws InvalidArgumentException - */ - public static function fromJson(array $json): BrushProperties - { - if (($json["version"] ?? 0) !== self::VERSION) throw new InvalidArgumentException("Version mismatch"); - $properties = new self; - foreach ($json as $key => $value) { - $properties->$key = $value; - } - return $properties; - } + /** + * @param array $json + * @return BrushProperties + * @throws InvalidArgumentException + */ + public static function fromJson(array $json): BrushProperties + { + if (($json["version"] ?? 0) !== self::VERSION) throw new InvalidArgumentException("Version mismatch"); + $properties = new self; + foreach ($json as $key => $value) { + $properties->$key = $value; + } + return $properties; + } - public function getName(): string - { - $str = ""; - try { - $str = trim(($this->hasCustomName() ? $this->customName : $this->getShapeName()) /*. " " . $this->action->getName() . */); - } catch (ShapeNotFoundException $e) { - } - if (stripos(TF::clean($str), "brush") === false) { - $str .= " Brush"; - } - return $str; - } + public function getName(): string + { + $str = ""; + try { + $str = trim(($this->hasCustomName() ? $this->customName : $this->getShapeName()) /*. " " . $this->action->getName() . */); + } catch (ShapeNotFoundException $e) { + } + if (stripos(TF::clean($str), "brush") === false) { + $str .= " Brush"; + } + return $str; + } - /** - * @return string - * @throws ShapeNotFoundException - */ - public function getShapeName(): string - { - return is_subclass_of($this->shape, Shape::class) ? ShapeRegistry::getShapeName($this->shape) : ""; - } + /** + * @return string + * @throws ShapeNotFoundException + */ + public function getShapeName(): string + { + return is_subclass_of($this->shape, Shape::class) ? ShapeRegistry::getShapeName($this->shape) : ""; + } - /** - * @return string - * @throws ActionNotFoundException - */ - public function getActionName(): string - { - return is_subclass_of($this->action, TaskAction::class) ? ActionRegistry::getActionName($this->action) : ""; - } + /** + * @return string + * @throws ActionNotFoundException + */ + public function getActionName(): string + { + return is_subclass_of($this->action, TaskAction::class) ? ActionRegistry::getActionName($this->action) : ""; + } - public function hasCustomName(): bool - { - return !empty($this->customName); - } + public function hasCustomName(): bool + { + return !empty($this->customName); + } - /** - * @param string $customName If empty, the name will be reset - */ - public function setCustomName(string $customName = ""): void - { - $this->customName = $customName; - } + /** + * @param string $customName If empty, the name will be reset + */ + public function setCustomName(string $customName = ""): void + { + $this->customName = $customName; + } - /** + /** * @return array * @throws ActionNotFoundException * @throws ShapeNotFoundException * @noinspection NestedTernaryOperatorInspection */ - public function generateLore(): array - { - $shapeProperties = array_map(static function ($k, $v): string { + public function generateLore(): array + { + $shapeProperties = array_map(static function ($k, $v): string { return TF::GOLD . " " . ucfirst($k) . " = " . (is_bool($v) ? ($v ? "Yes" : "No") : $v); }, array_keys($this->shapeProperties), $this->shapeProperties); $actionProperties = array_map(static function ($k, $v): string { return TF::GOLD . " " . ucfirst($k) . " = " . (is_bool($v) ? ($v ? "Yes" : "No") : $v); }, array_keys($this->actionProperties), $this->actionProperties); - return array_merge( - [ - TF::GOLD . "Shape: {$this->getShapeName()}", - ], - $shapeProperties, - [ - TF::GOLD . "Action: {$this->getActionName()}", - ], - $actionProperties, - [ - TF::GOLD . "Blocks: {$this->blocks}", - TF::GOLD . "Filter: {$this->filter}", - TF::GOLD . "Biome: {$this->biomeId}", - TF::GOLD . "Hollow: " . ($this->hollow ? "Yes" : "No"), - //TF::GOLD . "UUID: {$this->uuid}", - ] - ); - } + return array_merge( + [ + TF::GOLD . "Shape: {$this->getShapeName()}", + ], + $shapeProperties, + [ + TF::GOLD . "Action: {$this->getActionName()}", + ], + $actionProperties, + [ + TF::GOLD . "Blocks: {$this->blocks}", + TF::GOLD . "Filter: {$this->filter}", + TF::GOLD . "Biome: {$this->biomeId}", + TF::GOLD . "Hollow: " . ($this->hollow ? "Yes" : "No"), + //TF::GOLD . "UUID: {$this->uuid}", + ] + ); + } } \ No newline at end of file diff --git a/src/xenialdan/MagicWE2/tool/WETool.php b/src/xenialdan/MagicWE2/tool/WETool.php index 59295ec2..67222c03 100644 --- a/src/xenialdan/MagicWE2/tool/WETool.php +++ b/src/xenialdan/MagicWE2/tool/WETool.php @@ -7,6 +7,6 @@ abstract class WETool { - abstract public function getName(): string; + abstract public function getName(): string; } \ No newline at end of file