diff --git a/resources/mysql.sql b/resources/mysql.sql index 97edb8a..537bb5b 100644 --- a/resources/mysql.sql +++ b/resources/mysql.sql @@ -6,7 +6,7 @@ -- # { init CREATE TABLE IF NOT EXISTS skyblockspm_player ( - uuid VARCHAR(32) PRIMARY KEY, + uuid VARCHAR(36) PRIMARY KEY, name VARCHAR(32), skyblock TEXT DEFAULT '' ); @@ -44,7 +44,7 @@ WHERE uuid=:uuid; -- # { init CREATE TABLE IF NOT EXISTS skyblockspm_sb ( - uuid VARCHAR(32) PRIMARY KEY, + uuid VARCHAR(36) PRIMARY KEY, name VARCHAR(32), leader VARCHAR(32), members TEXT, diff --git a/resources/sqlite.sql b/resources/sqlite.sql index 239c46e..bdbb9f1 100644 --- a/resources/sqlite.sql +++ b/resources/sqlite.sql @@ -6,7 +6,7 @@ -- # { init CREATE TABLE IF NOT EXISTS skyblockspm_player ( - uuid VARCHAR(32) PRIMARY KEY, + uuid VARCHAR(36) PRIMARY KEY, name VARCHAR(32), skyblock TEXT DEFAULT '' ); @@ -44,7 +44,7 @@ WHERE uuid=:uuid; -- # { init CREATE TABLE IF NOT EXISTS skyblockspm_sb ( - uuid VARCHAR(32) PRIMARY KEY, + uuid VARCHAR(36) PRIMARY KEY, name VARCHAR(32), leader VARCHAR(32), members TEXT, diff --git a/src/Vecnavium/SkyBlocksPM/commands/args/IslandNameArgument.php b/src/Vecnavium/SkyBlocksPM/commands/args/IslandNameArgument.php new file mode 100644 index 0000000..cefcc59 --- /dev/null +++ b/src/Vecnavium/SkyBlocksPM/commands/args/IslandNameArgument.php @@ -0,0 +1,45 @@ +setPermission('skyblockspm.create'); - $this->registerArgument(0, new RawStringArgument('name')); + $this->registerArgument(0, new IslandNameArgument('name')); } /** @@ -47,9 +49,12 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo return; } $sender->sendMessage($plugin->getMessages()->getMessage('skyblock-creating')); - $id = Uuid::uuid4()->toString(); + + // Hotfix for those with pre-existing SkyBlocksPM databases where the UUID length is specified as 32, and not 36 + $id = substr(Uuid::uuid4()->toString(), 0, -4); + $player->setSkyBlock($id); - $plugin->getGenerator()->generateIsland($sender, $id, strval($args['name'])); // Name validation? + $plugin->getGenerator()->generateIsland($sender, $id, strval($args['name'])); } } diff --git a/src/Vecnavium/SkyBlocksPM/generator/Generator.php b/src/Vecnavium/SkyBlocksPM/generator/Generator.php index 6a311ea..215fca2 100644 --- a/src/Vecnavium/SkyBlocksPM/generator/Generator.php +++ b/src/Vecnavium/SkyBlocksPM/generator/Generator.php @@ -59,16 +59,16 @@ public function setIslandWorld(P $player): void { /** * @param P $player - * @param string $folderName + * @param string $uuid * @param string $name * * Thanks SkyWars by GamakCZ */ - public function generateIsland(P $player, string $folderName, string $name): void{ + public function generateIsland(P $player, string $uuid, string $name): void{ $path = $this->plugin->getDataFolder() . 'cache/island'; $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator((string)realpath($path)), RecursiveIteratorIterator::LEAVES_ONLY); - $path = $this->plugin->getServer()->getDataPath() . 'worlds' . DIRECTORY_SEPARATOR . $folderName; + $path = $this->plugin->getServer()->getDataPath() . 'worlds' . DIRECTORY_SEPARATOR . $uuid; @mkdir($path); @mkdir($path . '/db'); @@ -83,12 +83,12 @@ public function generateIsland(P $player, string $folderName, string $name): voi copy($filePath, $path . DIRECTORY_SEPARATOR . $localPath); } - $this->plugin->getServer()->getWorldManager()->loadWorld($folderName); - $world = $this->plugin->getServer()->getWorldManager()->getWorldByName($folderName); + $this->plugin->getServer()->getWorldManager()->loadWorld($uuid); + $world = $this->plugin->getServer()->getWorldManager()->getWorldByName($uuid); $skyBlockPlayer = $this->plugin->getPlayerManager()->getPlayer($player->getName()); if($world instanceof World && $skyBlockPlayer instanceof Player) { $player->teleport(Position::fromObject($world->getSpawnLocation(), $world)); - $this->plugin->getSkyBlockManager()->createSkyBlock($world->getFolderName(), $skyBlockPlayer, $name, $world); + $this->plugin->getSkyBlockManager()->createSkyBlock($uuid, $skyBlockPlayer, $name, $world); } } diff --git a/src/Vecnavium/SkyBlocksPM/player/PlayerManager.php b/src/Vecnavium/SkyBlocksPM/player/PlayerManager.php index ef03289..d236e1d 100644 --- a/src/Vecnavium/SkyBlocksPM/player/PlayerManager.php +++ b/src/Vecnavium/SkyBlocksPM/player/PlayerManager.php @@ -6,6 +6,7 @@ use pocketmine\player\Player as P; use Vecnavium\SkyBlocksPM\SkyBlocksPM; +use function substr; class PlayerManager { @@ -48,13 +49,15 @@ public function unloadPlayer(P $player): void{ } public function createPlayer(P $player): void { + // Hotfix for those with pre-existing SkyBlocksPM databases where the UUID length is specified as 32, and not 36 + $uuid = substr($player->getUniqueId()->toString(), 0, -4); $this->plugin->getDataBase()->executeInsert('skyblockspm.player.create', [ - 'uuid' => $player->getUniqueId()->toString(), + 'uuid' => $uuid, 'name' => $player->getName(), 'skyblock' => '' ]); - $this->players[$player->getName()] = new Player($player->getUniqueId()->toString(), $player->getName(), ''); + $this->players[$player->getName()] = new Player($uuid, $player->getName(), ''); } /**