Fixed Villager Trades for the last time
This commit is contained in:
@@ -10,6 +10,26 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
/**
|
||||
* Handle.
|
||||
*/
|
||||
private final Field handle;
|
||||
|
||||
/**
|
||||
* Create new Villager Trade.
|
||||
*/
|
||||
public VillagerTrade() {
|
||||
try {
|
||||
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||
@@ -35,10 +55,8 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@NotNull
|
||||
private net.minecraft.server.v1_16_R1.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||
try {
|
||||
Field handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return (net.minecraft.server.v1_16_R1.MerchantRecipe) handle.get(recipe);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,26 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
/**
|
||||
* Handle.
|
||||
*/
|
||||
private final Field handle;
|
||||
|
||||
/**
|
||||
* Create new Villager Trade.
|
||||
*/
|
||||
public VillagerTrade() {
|
||||
try {
|
||||
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||
@@ -35,10 +55,8 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@NotNull
|
||||
private net.minecraft.server.v1_16_R2.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||
try {
|
||||
Field handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return (net.minecraft.server.v1_16_R2.MerchantRecipe) handle.get(recipe);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,26 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
/**
|
||||
* Handle.
|
||||
*/
|
||||
private final Field handle;
|
||||
|
||||
/**
|
||||
* Create new Villager Trade.
|
||||
*/
|
||||
public VillagerTrade() {
|
||||
try {
|
||||
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||
@@ -35,10 +55,8 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@NotNull
|
||||
private net.minecraft.server.v1_16_R3.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||
try {
|
||||
Field handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
return (net.minecraft.server.v1_16_R3.MerchantRecipe) handle.get(recipe);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
/**
|
||||
@@ -29,10 +29,14 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
|
||||
|
||||
recipes = recipes.stream().peek(merchantRecipe -> InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(merchantRecipe)).collect(Collectors.toList());
|
||||
List<MerchantRecipe> recipes = new ArrayList<>();
|
||||
|
||||
packet.getMerchantRecipeLists().writeSafely(0, recipes);
|
||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||
MerchantRecipe newRecipe = InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
|
||||
recipes.add(newRecipe);
|
||||
}
|
||||
|
||||
packet.getMerchantRecipeLists().write(0, recipes);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user