Restoring inventory
woodchest opened this issue · 9 comments
Skript/Server Version
Skript's aliases can be found here: https://github.com/SkriptLang/skript-aliases
Skript's documentation can be found here: https://docs.skriptlang.org/
Skript's tutorials can be found here: https://docs.skriptlang.org/tutorials
Server Version: git-Paper-496 (MC: 1.20.4)
Skript Version: 2.8.6 (skriptlang-github)
Installed Skript Addons:
- skript-placeholders v1.6.0 (https://github.com/APickledWalrus/skript-placeholders)
- skript-gui v1.3 (https://github.com/APickledWalrus/skript-gui)
- Skellett v2.0.9 (https://forums.skunity.com/resources/skellett.24/)
- SkQuery v4.1.10
- SkBee v3.5.2 (https://github.com/ShaneBeee/SkBee)
Installed dependencies:
- Vault v1.7.3-b131
- WorldGuard v7.0.9+5934e49
Bug Description
Cannot restore inventory
Expected Behavior
After running /mod to turn it off, I should get my inventory back
Steps to Reproduce
command /mod [<string>] [<player>]:
permission: mod.use
trigger:
if arg-1 is not set:
if {mod.%player%} is not set:
set {inventory.%player%} to player's inventory
set gamemode of player to creative
execute player command "v"
execute console command "eci %player%"
message "&a» &eYou are now in moderator mode!"
set slot 1 of player to iron bars named "&6Freeze" with lore "&7Freeze someone for hacking!"
set slot 0 of player to book named "&6Examine" with lore "&7Use this to see someones inventory!"
set slot 2 of player to lime dye named "&aVanish" with lore "&7Use this to toggle your vanish!"
set slot 8 of player to clock named "&6Random TP" with lore "&7Use this to randomly tp to someone!"
set {mod.%player%} to true
stop
else:
execute console command "spawn %player%"
execute player command "v"
execute console command "eci %player%"
set player's inventory to {inventory.%player%}
message "&a» &EYou are no longer in moderator mode!"
clear {mod.%player%}
stop
if arg-1 is "tp":
if arg-2 is set:
if {mod.%player%} is set:
teleport player to arg-2
message "&eTeleporting you to &6%arg-2%&e!"
stop
else:
message "&c»&E Please go into moderator mode to use this feature!"
stop
Errors or Screenshots
1 error in console: Can't org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryPlayer@772f6f95 to an inventory!
Other
No response
Agreement
- I have read the guidelines above and affirm I am following them with this report.
That's the entire error.
" Can't org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryPlayer@772f6f95 to an inventory! "
After looking into some stuff a bit more this is the code that caused the above error, the issue is caused by skript allowing inventory but then proceeding to never add checks for it
if (mode == ChangeMode.SET)
return CollectionUtils.array(ItemType[].class, Inventory.class);
Skript/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
Lines 224 to 236 in e2928ce
Solution for now would probably be adding inventory support and updating the error message to be more specific and use Classes#toString
Tho I don't really know what inventory will do here, they're reference bases and the way he has is code setup would just set it to air again anyways
So? is it just impossible?
You should be saving a list of all the items in the player's inventory, rather than a reference to their inventory:
set {_items::*} to items in player's inventory
...
clear player's inventory
give {_items::*} to player
If you want to maintain the slots, you can do that via a loop and using index of loop-slot