Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Restoring inventory

Open woodchest opened this issue 1 year ago • 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

  • [X] I have read the guidelines above and affirm I am following them with this report.

woodchest avatar Jun 24 '24 15:06 woodchest

Have you tried without SkQuery?

EquipableMC avatar Jun 24 '24 16:06 EquipableMC

Have you tried without SkQuery?

Hey, I did. Didn't work

woodchest avatar Jun 24 '24 16:06 woodchest

can you post the entire error please?

Pikachu920 avatar Jun 24 '24 16:06 Pikachu920

That's the entire error. " Can't org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryPlayer@772f6f95 to an inventory! "

woodchest avatar Jun 24 '24 16:06 woodchest

there should be more lines before and after that

Pikachu920 avatar Jun 24 '24 16:06 Pikachu920

there should be more lines before and after that

Screenshot_2

woodchest avatar Jun 24 '24 16:06 woodchest

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);

https://github.com/SkriptLang/Skript/blob/e2928ceae90c94beabe51240358d401b22524fba/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java#L224-L236

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

Fusezion avatar Jun 24 '24 17:06 Fusezion

So? is it just impossible?

woodchest avatar Jun 24 '24 18:06 woodchest

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

sovdeeth avatar Jun 24 '24 18:06 sovdeeth