mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-03 02:21:21 +01:00
Fix villager trades not displaying a lore
In order to fix this issue, I had to do the following: - Bump ProtocolLib version to 4.6.0 (getting the latest version is enough) - Intercepted the OPEN_WINDOW_MERCHANT and updated the trades' result to include the enchantments. Do note that the items still will only have a lore at the client-side.
This commit is contained in:
parent
33c0caabb9
commit
9a3acbe725
@ -245,7 +245,7 @@
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.5.0</version>
|
||||
<version>4.6.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -4,15 +4,18 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.ecoenchants.Main;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayPacketAdapter extends PacketAdapter {
|
||||
private static final List<PacketType> packets = Arrays.asList(
|
||||
PacketType.Play.Server.WINDOW_ITEMS,
|
||||
PacketType.Play.Server.SET_SLOT,
|
||||
PacketType.Play.Client.SET_CREATIVE_SLOT
|
||||
PacketType.Play.Client.SET_CREATIVE_SLOT,
|
||||
PacketType.Play.Server.OPEN_WINDOW_MERCHANT
|
||||
);
|
||||
|
||||
public DisplayPacketAdapter() {
|
||||
@ -34,6 +37,24 @@ public class DisplayPacketAdapter extends PacketAdapter {
|
||||
item = EnchantDisplay.displayEnchantments(item);
|
||||
return item;
|
||||
});
|
||||
} else if (PacketType.Play.Server.OPEN_WINDOW_MERCHANT.equals(packetType)) {
|
||||
List<MerchantRecipe> merchantRecipes = event.getPacket().getMerchantRecipeLists().readSafely(0);
|
||||
if (merchantRecipes != null) {
|
||||
List<MerchantRecipe> newList =
|
||||
merchantRecipes.stream().map(oldRecipe -> {
|
||||
MerchantRecipe recipe =
|
||||
new MerchantRecipe(EnchantDisplay.displayEnchantments(oldRecipe.getResult()),
|
||||
oldRecipe.getUses(),
|
||||
oldRecipe.getMaxUses(),
|
||||
oldRecipe.hasExperienceReward(),
|
||||
oldRecipe.getVillagerExperience(),
|
||||
oldRecipe.getPriceMultiplier());
|
||||
recipe.setIngredients(oldRecipe.getIngredients());
|
||||
return recipe;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
event.getPacket().getMerchantRecipeLists().writeSafely(0, newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user