Twelvee
November 16, 2017, 9:04am
1
Hello.
How I Can track if user crafted the item?
Trying to do smth like:
@Listener
public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter (“getTargetInventory”) Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
Inventory craftingOutputs = inventory.query(CraftingOutput.class);
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");
}));
}
But, have a problem, player get message after compile items at workbench to create smth.
How to check if user click on crafting output field?
Check the transactions in event.getTransactions()
- for each one, check if its slot is a CraftingOutput
.
Twelvee
November 17, 2017, 4:25pm
3
pie_flavor:
event.getTransactions()
So, how I can do it?
Please help
… what?
Are you asking how to call a method?
Twelvee
November 19, 2017, 9:10am
5
Yep, sorry, but I’m so dumb for this…
if(event.getTransactions().equals(craftingOutputs)){
Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");
}
This code doesn’t work
Twelvee
November 19, 2017, 9:44am
6
Now trying do this:
Inventory craftingOutputs = inventory.query(CraftingOutput.class);
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
for (Iterator<SlotTransaction> i = event.getTransactions().iterator(); i.hasNext();) {
SlotTransaction item = i.next();
if(item.getSlot().equals(slot)){
Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");
}
}
}));
Not success, again
Twelvee
November 19, 2017, 10:57am
7
The main question is - how I Can get the craftring output slot?
JBYoshi
November 20, 2017, 4:06am
8
In the line Inventory craftingOutputs = inventory.query(CraftingOutput.class);
, replace Inventory craftingOutputs
with CraftingOutput slot
. This is the crafting output slot. You don’t need to use slots()
with this.