diff --git a/data/rx.playerdb/functions/admin/migrate_account.mcfunction b/data/rx.playerdb/functions/admin/migrate_account.mcfunction new file mode 100644 index 0000000..b9684b8 --- /dev/null +++ b/data/rx.playerdb/functions/admin/migrate_account.mcfunction @@ -0,0 +1,16 @@ +# By: rx97 +# 25 Apr 21 +# +#> @s: player to migrate +#> Migrates old player data to new @s account +#> - input: rx:temp playerdb.admin.migrate.UUID +#> - set as UUID array of old account +#> - output: +#> - @s will have old rx.uid and old data + +#> WARNING: This will nuke your current data and replace it +#> with the other accounts data. Do take backups! + +#> run migration if we have data +execute unless data storage rx:temp playerdb.admin.migrate.UUID run tellraw @a[tag=rx.admin] [{"text": "", "color":"gray"}, {"storage": "rx:info", "nbt": "playerdb.pretty_name", "interpret": true}, ": ", {"text": "Migration failed. Input in ", "color": "#CE4257"}, {"text": "rx:temp playerdb.admin.migrate", "color": "gold"}, {"text": " is empty.", "color": "#CE4257"}] +execute if data storage rx:temp playerdb.admin.migrate.UUID run function rx.playerdb:impl/admin/migrate_account diff --git a/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction b/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction new file mode 100644 index 0000000..dcbd92b --- /dev/null +++ b/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction @@ -0,0 +1,44 @@ +# By: rx97 +# 25 Apr 21 +# +#> @s: player +#> Once we've found the acc, migrate! + +#> grab our uid and other data then nuke +execute store result score $migrate.uid rx.temp run data get storage rx:global playerdb.uuid[{selected:1b}].entries[-1].uid +execute store result score $migrate.hasEntry rx.temp run data get storage rx:global playerdb.uuid[{selected:1b}].entries[-1].hasEntry +data modify storage rx:temp playerdb.admin.migrate.oldName set from storage rx:global playerdb.uuid[{selected:1b}].entries[-1].name +data remove storage rx:global playerdb.uuid[{selected:1b}].entries[-1] + +#> nuke our current entry if it exists +execute if score @s rx.pdb.HasEntry matches 1.. run scoreboard players operation $in.uid rx.io = @s rx.uid +execute if score @s rx.pdb.HasEntry matches 1.. run function rx.playerdb:api/select +execute if score @s rx.pdb.HasEntry matches 1.. run data remove storage rx:global playerdb.players[{selected:1b}] + +#> restore our old uid and data +scoreboard players operation @s rx.uid = $migrate.uid rx.temp +scoreboard players operation @s rx.pdb.HasEntry = $migrate.hasEntry rx.temp + +# also update name while we are at it +execute if score @s rx.pdb.HasEntry matches 1.. run function rx.playerdb:api/get_self +execute if score @s rx.pdb.HasEntry matches 1.. run data modify storage rx:global playerdb.players[{selected:1b}].info.UUID set from entity @s UUID +execute if score @s rx.pdb.HasEntry matches 1.. run function rx.playerdb:impl/get_name +execute if score @s rx.pdb.HasEntry matches 1.. run data modify storage rx:global playerdb.players[{selected:1b}].info.name set from storage rx:temp playerdb.player_name +execute if score @s rx.pdb.HasEntry matches 1.. run function rx.playerdb:api/save_self + +#> update our current UUID entry w/ the original uid +scoreboard players operation $uid rx.temp = @s rx.uuid0 +function rx.playerdb:impl/uuid/select +execute store result storage rx:global playerdb.uuid[{selected:1b}].entries[-1].uid byte 1 run scoreboard players get @s rx.uid +execute store result storage rx:global playerdb.uuid[{selected:1b}].entries[-1].hasEntry byte 1 run scoreboard players get @s rx.pdb.HasEntry + +#> tellraw a success msg :D +tellraw @a[tag=rx.admin] [{"text": "", "color": "green"}, {"storage": "rx:info", "nbt": "playerdb.pretty_name", "interpret": true}, ": ", {"storage": "rx:temp", "nbt": "playerdb.admin.migrate.oldName", "color": "gold"}, "'s data was migrated to ", {"selector": "@s", "color": "gold"}] +tellraw @a[tag=rx.admin] [{"text": "", "color": "gray"}, {"storage": "rx:info", "nbt": "playerdb.pretty_name", "interpret": true}, ": Run `/scoreboard players reset ", {"storage": "rx:temp", "nbt": "playerdb.admin.migrate.oldName", "color": "gold"}, "` to complete the migration process!"] +tellraw @s [{"text": "", "color": "green"}, {"storage": "rx:info", "nbt": "playerdb.pretty_name", "interpret": true}, ": ", {"storage": "rx:temp", "nbt": "playerdb.admin.migrate.oldName", "color": "gold"}, "'s data was successfully migrated to you!"] + +#> call name change api +function #rx.playerdb:api/on_name_change + +#> cleanup +data remove storage rx:temp playerdb.admin.migrate diff --git a/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction b/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction new file mode 100644 index 0000000..cf2a6a7 --- /dev/null +++ b/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction @@ -0,0 +1,14 @@ +# By: rx97 +# 25 Apr 21 +# +#> @s: player to migrate +#> Starts migration process + +#> First, let's get our entry +execute store result score $uid rx.temp run data get storage rx:temp playerdb.admin.migrate.UUID[0] +function rx.playerdb:impl/uuid/select + +execute if score $found rx.temp matches 0 run tellraw @a[tag=rx.admin] [{"text": "", "color":"gray"}, {"storage": "rx:info", "nbt": "playerdb.pretty_name", "interpret": true}, ": ", {"text": "Migration failed. Input UUID account not found.", "color": "#CE4257"}] + +#> found entry +execute if score $found rx.temp matches 1 run function rx.playerdb:impl/admin/migrate/found_acc