From 9ea91366eebe3942948a50233683f6650476520d Mon Sep 17 00:00:00 2001 From: Ritik Shah Date: Sun, 25 Apr 2021 17:55:17 -0700 Subject: [PATCH 1/3] rx: finished implementation --- .../admin/migrate_account.mcfunction | 13 ++++++ .../impl/admin/migrate/found_acc.mcfunction | 40 +++++++++++++++++++ .../impl/admin/migrate_account.mcfunction | 14 +++++++ 3 files changed, 67 insertions(+) create mode 100644 data/rx.playerdb/functions/admin/migrate_account.mcfunction create mode 100644 data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction create mode 100644 data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction 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..75282c6 --- /dev/null +++ b/data/rx.playerdb/functions/admin/migrate_account.mcfunction @@ -0,0 +1,13 @@ +# 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 + +#> 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": "red"}, {"text": "rx:temp playerdb.admin.migrate", "color": "gold"}, {"text": " is empty.", "color": "red"}] +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..9084399 --- /dev/null +++ b/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction @@ -0,0 +1,40 @@ +# 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 @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!"] + +#> 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..c0de3bd --- /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": "red"}] + +#> found entry +execute if score $found rx.temp matches 1 run function rx.playerdb:impl/admin/migrate/found_acc From 0d615e9fdc070b722f343c083fdde4710c5d5f23 Mon Sep 17 00:00:00 2001 From: Ritik Shah Date: Sun, 25 Apr 2021 18:07:14 -0700 Subject: [PATCH 2/3] rx: finishing touches, calls name_change api, etc --- data/rx.playerdb/functions/admin/migrate_account.mcfunction | 3 +++ .../functions/impl/admin/migrate/found_acc.mcfunction | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/data/rx.playerdb/functions/admin/migrate_account.mcfunction b/data/rx.playerdb/functions/admin/migrate_account.mcfunction index 75282c6..ce080c2 100644 --- a/data/rx.playerdb/functions/admin/migrate_account.mcfunction +++ b/data/rx.playerdb/functions/admin/migrate_account.mcfunction @@ -8,6 +8,9 @@ #> - 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": "red"}, {"text": "rx:temp playerdb.admin.migrate", "color": "gold"}, {"text": " is empty.", "color": "red"}] 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 index 9084399..dcbd92b 100644 --- a/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction +++ b/data/rx.playerdb/functions/impl/admin/migrate/found_acc.mcfunction @@ -34,7 +34,11 @@ execute store result storage rx:global playerdb.uuid[{selected:1b}].entries[-1]. #> 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 From 96b861cb5977c89c298ea04b9a3bd146b1180a0b Mon Sep 17 00:00:00 2001 From: Ritik Shah Date: Sun, 25 Apr 2021 18:13:08 -0700 Subject: [PATCH 3/3] rx: changed the color of red --- data/rx.playerdb/functions/admin/migrate_account.mcfunction | 2 +- .../rx.playerdb/functions/impl/admin/migrate_account.mcfunction | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/rx.playerdb/functions/admin/migrate_account.mcfunction b/data/rx.playerdb/functions/admin/migrate_account.mcfunction index ce080c2..b9684b8 100644 --- a/data/rx.playerdb/functions/admin/migrate_account.mcfunction +++ b/data/rx.playerdb/functions/admin/migrate_account.mcfunction @@ -12,5 +12,5 @@ #> 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": "red"}, {"text": "rx:temp playerdb.admin.migrate", "color": "gold"}, {"text": " is empty.", "color": "red"}] +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_account.mcfunction b/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction index c0de3bd..cf2a6a7 100644 --- a/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction +++ b/data/rx.playerdb/functions/impl/admin/migrate_account.mcfunction @@ -8,7 +8,7 @@ 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": "red"}] +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