Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring inventory #6814

Open
1 task done
woodchest opened this issue Jun 24, 2024 · 9 comments
Open
1 task done

Restoring inventory #6814

woodchest opened this issue Jun 24, 2024 · 9 comments
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions.

Comments

@woodchest
Copy link

woodchest commented Jun 24, 2024

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.
@EquipableMC
Copy link
Contributor

Have you tried without SkQuery?

@woodchest
Copy link
Author

Have you tried without SkQuery?

Hey, I did.
Didn't work

@Pikachu920
Copy link
Member

can you post the entire error please?

@Pikachu920 Pikachu920 added the waiting for reply The report needs a response from the reporter to determine course of action. label Jun 24, 2024
@woodchest
Copy link
Author

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

@Pikachu920
Copy link
Member

there should be more lines before and after that

@woodchest
Copy link
Author

there should be more lines before and after that

Screenshot_2

@Fusezion
Copy link
Contributor

Fusezion commented Jun 24, 2024

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

} else {
for (final Object d : delta) {
if (d instanceof ItemStack) {
new ItemType((ItemStack) d).addTo(invi); // Can't imagine why would be ItemStack, but just in case...
} else if (d instanceof ItemType) {
((ItemType) d).addTo(invi);
} else if (d instanceof Block) {
new ItemType((Block) d).addTo(invi);
} else {
Skript.error("Can't " + d.toString() + " to an inventory!");
}
}
}

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

@woodchest
Copy link
Author

So? is it just impossible?

@sovdeeth
Copy link
Member

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 sovdeeth added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. and removed waiting for reply The report needs a response from the reporter to determine course of action. labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions.
Projects
None yet
Development

No branches or pull requests

5 participants