Cannot modify merchant recipes in OPEN_WINDOW_MERCHANT packet
Rothes opened this issue ยท 3 comments
Describe the bug
Cannot modify merchant recipes in OPEN_WINDOW_MERCHANT packet.
To Reproduce
Code:
StructureModifier<List<MerchantRecipe>> merchantRecipeLists = packetEvent.getPacket().getMerchantRecipeLists();
List<MerchantRecipe> read = merchantRecipeLists.read(0);
for (MerchantRecipe recipe : read) {
ProtocolStringReplacer.info("recipe!!!");
for (ItemStack ingredient : recipe.getIngredients()) {
replaceItemStack(packetEvent, user, listenType, ingredient, filter);
}
recipe.getIngredients().add(new ItemStack(Material.STONE));
ProtocolStringReplacer.info("Original result name is: " + recipe.getResult().getItemMeta().getDisplayName());
replaceItemStack(packetEvent, user, listenType, recipe.getResult(), filter);
}
merchantRecipeLists.write(0, read);
for (MerchantRecipe recipe : packetEvent.getPacket().getMerchantRecipeLists().read(0)) {
if (recipe.getIngredients().size() > 1) {
ProtocolStringReplacer.info("Stone is added");
}
ProtocolStringReplacer.info("Wrote is: " + recipe.getResult().getItemMeta().getDisplayName());
}
- Or GitHub here (Clean version)
See console logs:
[23:38:33] [Server thread/INFO]: [ProtocolStringReplacer] recipe!!!
[23:38:33] [Server thread/INFO]: [ProtocolStringReplacer] Original result name is: Original Not Edited
[23:38:33] [Server thread/INFO]: [ProtocolStringReplacer] Stone is added
[23:38:33] [Server thread/INFO]: [ProtocolStringReplacer] Wrote is: Edited!!!
Expected behavior
modify the recipes in game.
Version Info
Server: This server is running CraftBukkit version 3488-Spigot-b6d12d1-d48f2d1 (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT)
ProtocolLib v4.8.0 download on Spigotmc