Skip to content

Commit

Permalink
Schematics, Structures and exported Clipboards: unified as "Assets"
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
inxomnyaa committed Feb 13, 2021
1 parent f5f1392 commit ded5dad
Show file tree
Hide file tree
Showing 84 changed files with 2,079 additions and 1,862 deletions.
3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/xenialdan/MagicWE2/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] */
Expand Down Expand Up @@ -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;
}
}
30 changes: 27 additions & 3 deletions src/xenialdan/MagicWE2/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -229,6 +247,12 @@ private function onRightClickBlock(PlayerInteractEvent $event): void
#}
break;
}
default:
{
var_dump($event->getItem());
$event->cancel();
break;
}
}
}
}
Expand Down
38 changes: 9 additions & 29 deletions src/xenialdan/MagicWE2/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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();
Expand Down
50 changes: 25 additions & 25 deletions src/xenialdan/MagicWE2/clipboard/Clipboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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;
}
}
14 changes: 7 additions & 7 deletions src/xenialdan/MagicWE2/clipboard/RevertClipboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,7 +53,7 @@ public function serialize()
]);
}

/**
/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
Expand All @@ -63,8 +63,8 @@ public function serialize()
* @since 5.1.0
* @noinspection PhpMissingParamTypeInspection
*/
public function unserialize($serialized)
{
public function unserialize($serialized)
{
[
$this->worldId,
$chunks,
Expand Down
42 changes: 21 additions & 21 deletions src/xenialdan/MagicWE2/clipboard/SingleClipboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]*/);
}
}
}
28 changes: 14 additions & 14 deletions src/xenialdan/MagicWE2/commands/DonateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit ded5dad

Please sign in to comment.