Skip to content

Implement kits placing items in specific slots#5794

Merged
JRoy merged 4 commits intoEssentialsX:2.xfrom
TiagoFar78:kitWithGearSlots
Feb 7, 2026
Merged

Implement kits placing items in specific slots#5794
JRoy merged 4 commits intoEssentialsX:2.xfrom
TiagoFar78:kitWithGearSlots

Conversation

@TiagoFar78
Copy link
Contributor

@TiagoFar78 TiagoFar78 commented May 7, 2024

Closes #5535

Copy link
Member

@JRoy JRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, sorry for the delay in review. overall, i think this pr is the wrong approach. we should be adding a slot:<number> into MetaItemStack where expandItems will attempt to add the item to that slot if it is not full.

@TiagoFar78
Copy link
Contributor Author

we should be adding a slot:<number> into MetaItemStack

I like the idea of storing the item slot like that, but it should not live in MetaItemStack. The slot is an inventory attribute, not an item attribute. If you put it in the item metadata, any serialization provider that saves only the item would lose the slot information and be unable to restore it later.

if (kitItem.startsWith("@")) {
	if (serializationProvider == null) {
		ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("kitError3", kitName, user.getName())));
		continue;
	}
	stack = serializationProvider.deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
} else {
	final String[] parts = kitItem.split(" +");
	final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

	if (parseStack.getType() == Material.AIR) {
		continue;
	}

	final MetaItemStack metaStack = new MetaItemStack(parseStack);

	if (parts.length > 2) {
		// We pass a null sender here because kits should not do perm checks
		metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
	}

	stack = metaStack.getItemStack();
}

itemList.add(stack);

where expandItems will attempt to add the item to that slot if it is not full.

Should expandItems try to place every item from a kit into its assigned slot rather than only armor and offhand, and if it does, should the command include a flag to disable this behavior? Editing the config to remove slot data is technically possible.

@JRoy
Copy link
Member

JRoy commented Dec 7, 2025

hmm you're right, it should stay in expandItems.

Instead of an slotList tho, lets do a HashMap<Integer, ItemStack>, if during put() we get a return value (overlapping slot), add it to the regular itemList .

then we should do the Inventories#hasSpace check with all items (both regular and slotted) (or isDropItemsIfFull)

then we'll have a new method in Inventories that will check isSimilar and if the amount + new amount will be greater than the allowed max size. that method will return a boolean if it can be added to the slot or not.

then finally add all the non-slotted items + ones that couldn't be added to the slot they asked for in one go via Inventories#addItem

@JRoy JRoy enabled auto-merge February 7, 2026 05:49
@JRoy
Copy link
Member

JRoy commented Feb 7, 2026

thank you!

@JRoy JRoy added this pull request to the merge queue Feb 7, 2026
Merged via the queue into EssentialsX:2.x with commit 6ab56d2 Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option for placing items in specific slots (offhand, armor, etc)

2 participants