Skip to content

Commit

Permalink
Updates, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VixikHD committed May 10, 2021
1 parent 54e859a commit 0f06b83
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 134 deletions.
10 changes: 8 additions & 2 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
# Target BuilderTools version: 1.2.0-beta4

# Do not change this line.
config-version: 1.2.0.2
config-version: 1.2.0.3

# This is format which will be used for creating schematics
# Supported formats: 'mcedit', 'mcstructure'
# Supported formats: 'mcedit', 'mcstructure', 'buildertools'
output-schematics-format: 'mcedit'

# Option for compressing clipboards. This will make the actions
# slower, but reduces RAM usage.
clipboard-compression: false

# Some shapes are generated with duplicate blocks. This problem causes
# some blocks are not reverted right when doing //undo. This option
# is for removing duplicates.
# Warning: This action takes around 98% time of the whole process!
remove-duplicate-blocks: true

# BuilderTools saves player's clipboard, undo & redo stuff when player
# leaves server to disk. This cache should be cleaned after restart (to
# avoid unexpected bugs). This option is to disable removing those files.
Expand Down
24 changes: 10 additions & 14 deletions src/czechpmdevs/buildertools/BuilderTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

class BuilderTools extends PluginBase {

public const CURRENT_CONFIG_VERSION = "1.2.0.2";
public const CURRENT_CONFIG_VERSION = "1.2.0.3";

/** @var BuilderTools */
private static BuilderTools $instance;
Expand All @@ -87,7 +87,7 @@ class BuilderTools extends PluginBase {

/** @noinspection PhpUnused */
public function onEnable() {
self::$instance = $this;
BuilderTools::$instance = $this;

$this->initConfig();
$this->cleanCache();
Expand Down Expand Up @@ -120,15 +120,11 @@ private function initConfig(): void {
}

$configuration = $this->getConfig()->getAll();
$needUpdate = false;
if(
!array_key_exists("config-version", $configuration) ||
version_compare((string)$configuration["config-version"], BuilderTools::CURRENT_CONFIG_VERSION) < 0
) {
$needUpdate = true;
}

if($needUpdate) {
// Update is required
@unlink($this->getDataFolder() . "config.yml.old");
@rename($this->getDataFolder() . "config.yml", $this->getDataFolder() . "config.yml.old");

Expand All @@ -140,12 +136,12 @@ private function initConfig(): void {
}

private function initListener(): void {
$this->getServer()->getPluginManager()->registerEvents(self::$listener = new EventListener(), $this);
$this->getServer()->getPluginManager()->registerEvents(BuilderTools::$listener = new EventListener(), $this);
}

private function registerCommands(): void {
$map = $this->getServer()->getCommandMap();
self::$commands = [
BuilderTools::$commands = [
new BiomeCommand,
new BlockInfoCommand,
new CenterCommand,
Expand Down Expand Up @@ -185,7 +181,7 @@ private function registerCommands(): void {
new WandCommand
];

foreach (self::$commands as $command) {
foreach (BuilderTools::$commands as $command) {
$map->register("BuilderTools", $command);
}

Expand Down Expand Up @@ -222,22 +218,22 @@ public function cleanCache(): void {
* @return Command[]
*/
public static function getAllCommands(): array {
return self::$commands;
return BuilderTools::$commands;
}

public static function getPrefix(): string {
return self::$prefix;
return BuilderTools::$prefix;
}

/**
* @noinspection PhpPluralMixedCanBeReplacedWithArrayInspection
* @phpstan-return mixed[]
*/
public static function getConfiguration(): array {
return self::$instance->getConfig()->getAll();
return BuilderTools::$instance->getConfig()->getAll();
}

public static function getInstance(): BuilderTools {
return self::$instance;
return BuilderTools::$instance;
}
}
18 changes: 9 additions & 9 deletions src/czechpmdevs/buildertools/ClipboardManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,38 @@ class ClipboardManager {
public static array $redoData = [];

public static function getClipboard(Player $player): ?SelectionData {
return clone self::$clipboards[$player->getName()] ?? null;
return clone ClipboardManager::$clipboards[$player->getName()] ?? null;
}

public static function hasClipboardCopied(Player $player): bool {
return array_key_exists($player->getName(), self::$clipboards);
return array_key_exists($player->getName(), ClipboardManager::$clipboards);
}

public static function saveClipboard(Player $player, SelectionData $data): void {
self::$clipboards[$player->getName()] = $data;
ClipboardManager::$clipboards[$player->getName()] = $data;
}

public static function getNextUndoAction(Player $player): ?BlockArray {
return array_pop(self::$undoData[$player->getName()]);
return array_pop(ClipboardManager::$undoData[$player->getName()]);
}

public static function hasActionToUndo(Player $player): bool {
return array_key_exists($player->getName(), self::$undoData) && !empty(self::$undoData[$player->getName()]);
return array_key_exists($player->getName(), ClipboardManager::$undoData) && !empty(ClipboardManager::$undoData[$player->getName()]);
}

public static function saveUndo(Player $player, BlockArray $array): void {
self::$undoData[$player->getName()][] = $array;
ClipboardManager::$undoData[$player->getName()][] = $array;
}

public static function getNextRedoAction(Player $player): ?BlockArray {
return array_pop(self::$redoData[$player->getName()]);
return array_pop(ClipboardManager::$redoData[$player->getName()]);
}

public static function hasActionToRedo(Player $player): bool {
return array_key_exists($player->getName(), self::$redoData) && !empty(self::$redoData[$player->getName()]);
return array_key_exists($player->getName(), ClipboardManager::$redoData) && !empty(ClipboardManager::$redoData[$player->getName()]);
}

public static function saveRedo(Player $player, BlockArray $array): void {
self::$redoData[$player->getName()][] = $array;
ClipboardManager::$redoData[$player->getName()][] = $array;
}
}
54 changes: 27 additions & 27 deletions src/czechpmdevs/buildertools/Selectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ class Selectors {
private static array $blockInfoPlayers = [];

public static function addDrawingPlayer(Player $player, int $brush, int $mode, bool $fall): void {
self::$drawingPlayers[$player->getName()] = [$brush, $mode, $fall];
Selectors::$drawingPlayers[$player->getName()] = [$brush, $mode, $fall];
}

public static function removeDrawingPlayer(Player $player): void {
unset(self::$drawingPlayers[$player->getName()]);
unset(Selectors::$drawingPlayers[$player->getName()]);
}

public static function getDrawingPlayerBrush(Player $player): int {
return self::$drawingPlayers[$player->getName()][0];
return Selectors::$drawingPlayers[$player->getName()][0];
}

public static function getDrawingPlayerMode(Player $player): int {
return self::$drawingPlayers[$player->getName()][1];
return Selectors::$drawingPlayers[$player->getName()][1];
}

public static function getDrawingPlayerFall(Player $player): bool {
return self::$drawingPlayers[$player->getName()][2];
return Selectors::$drawingPlayers[$player->getName()][2];
}

public static function isDrawingPlayer(Player $player): bool {
return array_key_exists($player->getName(), self::$drawingPlayers);
return array_key_exists($player->getName(), Selectors::$drawingPlayers);
}

/**
Expand All @@ -77,13 +77,13 @@ public static function addSelector(Player $player, int $pos, Position $position)
}

if($pos == 1) {
self::$pos1[$player->getName()] = $position;
Selectors::$pos1[$player->getName()] = $position;
} else {
self::$pos2[$player->getName()] = $position;
Selectors::$pos2[$player->getName()] = $position;
}

$pos1 = self::$pos1[$player->getName()] ?? null;
$pos2 = self::$pos2[$player->getName()] ?? null;
$pos1 = Selectors::$pos1[$player->getName()] ?? null;
$pos2 = Selectors::$pos2[$player->getName()] ?? null;

if($pos1 === null || $pos2 === null) {
return null;
Expand All @@ -106,56 +106,56 @@ public static function addSelector(Player $player, int $pos, Position $position)

public static function getPosition(Player $player, int $pos): ?Position {
if($pos == 1) {
return self::$pos1[$player->getName()];
return Selectors::$pos1[$player->getName()];
}
if($pos == 2) {
return self::$pos2[$player->getName()];
return Selectors::$pos2[$player->getName()];
}

return null;
}

public static function isSelected(int $pos, Player $player): bool {
if($pos == 1) {
return array_key_exists($player->getName(), self::$pos1);
return array_key_exists($player->getName(), Selectors::$pos1);
}
if($pos == 2) {
return array_key_exists($player->getName(), self::$pos2);
return array_key_exists($player->getName(), Selectors::$pos2);
}

return false;
}

public static function switchWandSelector(Player $player): void {
if(array_key_exists($player->getName(), self::$wandSelectors)) {
unset(self::$wandSelectors[$player->getName()]);
if(array_key_exists($player->getName(), Selectors::$wandSelectors)) {
unset(Selectors::$wandSelectors[$player->getName()]);
} else {
self::$wandSelectors[$player->getName()] = $player;
Selectors::$wandSelectors[$player->getName()] = $player;
}
}

public static function switchBlockInfoSelector(Player $player): void {
if(array_key_exists($player->getName(), self::$blockInfoPlayers)) {
unset(self::$blockInfoPlayers[$player->getName()]);
if(array_key_exists($player->getName(), Selectors::$blockInfoPlayers)) {
unset(Selectors::$blockInfoPlayers[$player->getName()]);
} else {
self::$blockInfoPlayers[$player->getName()] = $player;
Selectors::$blockInfoPlayers[$player->getName()] = $player;
}
}

public static function isWandSelector(Player $player): bool {
return array_key_exists($player->getName(), self::$wandSelectors);
return array_key_exists($player->getName(), Selectors::$wandSelectors);
}

public static function isBlockInfoPlayer(Player $player): bool {
return array_key_exists($player->getName(), self::$blockInfoPlayers);
return array_key_exists($player->getName(), Selectors::$blockInfoPlayers);
}

public static function unloadPlayer(Player $player): void {
unset(self::$wandSelectors[$player->getName()]);
unset(self::$blockInfoPlayers[$player->getName()]);
unset(self::$drawingPlayers[$player->getName()]);
unset(Selectors::$wandSelectors[$player->getName()]);
unset(Selectors::$blockInfoPlayers[$player->getName()]);
unset(Selectors::$drawingPlayers[$player->getName()]);

unset(self::$pos1[$player->getName()]);
unset(self::$pos2[$player->getName()]);
unset(Selectors::$pos1[$player->getName()]);
unset(Selectors::$pos2[$player->getName()]);
}
}
4 changes: 2 additions & 2 deletions src/czechpmdevs/buildertools/async/AsyncQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function submitTask(BuilderToolsAsyncTask $task, ?Closure $callbac
Server::getInstance()->getAsyncPool()->submitTask($task);

if($callback !== null) {
self::$queue[$task->getTaskId()] = $callback;
AsyncQueue::$queue[$task->getTaskId()] = $callback;
}
}

Expand All @@ -54,7 +54,7 @@ public static function callCallback(BuilderToolsAsyncTask $task): void {
return;
}

$callback = self::$queue[$task->getTaskId()];
$callback = AsyncQueue::$queue[$task->getTaskId()];
$callback($task);
}
}
4 changes: 4 additions & 0 deletions src/czechpmdevs/buildertools/async/convert/WorldFixTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class WorldFixTask extends AsyncTask {
/** @var bool */
public bool $done = false;

/** @var int */
public int $percent = 0;

/** @var float */
public float $time = 0.0;
/** @var int */
Expand Down Expand Up @@ -140,6 +143,7 @@ public function onRun() {

MainLogger::getLogger()->debug("[BuilderTools] World is fixed from $percent% ($regionsFixed/$regionCount regions), $chunksFixed chunks fixed with speed of $timePerChunk seconds per chunk. Expected time: $expectedTime.");

$this->percent = (int)$percent;
$provider->doGarbageCollection();
}

Expand Down
21 changes: 21 additions & 0 deletions src/czechpmdevs/buildertools/blockstorage/BlockArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use Serializable;
use function array_combine;
use function array_keys;
use function array_reverse;
use function array_slice;
use function array_unique;
use function array_values;
use function count;
use function in_array;
use function is_string;
use function microtime;
use function pack;
use function unpack;
use const SORT_REGULAR;

class BlockArray implements UpdateLevelData, Serializable {

Expand Down Expand Up @@ -181,6 +187,21 @@ public function getCoordsArray(): array {
return $this->coords;
}

public function removeDuplicates(): void {
if(!(BuilderTools::getConfiguration()["remove-duplicate-blocks"] ?? true)) {
return;
}

// TODO - Optimize this
$blocks = array_combine(array_reverse($this->coords, true), array_reverse($this->blocks, true));
if($blocks === false) {
return;
}

$this->coords = array_keys($blocks);
$this->blocks = array_values($blocks);
}

public function save(): void {
if(BuilderTools::getConfiguration()["clipboard-compression"] ?? false) {
$this->compress();
Expand Down
2 changes: 1 addition & 1 deletion src/czechpmdevs/buildertools/commands/BiomeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BiomeCommand extends BuilderToolsCommand {

public function __construct() {
parent::__construct("/biome", "Updates biome for the selection");
$this->biomeData = json_decode(self::BIOME_DATA, true);
$this->biomeData = json_decode(BiomeCommand::BIOME_DATA, true);
}

public function execute(CommandSender $sender, string $commandLabel, array $args) {
Expand Down
Loading

0 comments on commit 0f06b83

Please sign in to comment.