Added fix for PacketPlayOutRecipeUpdate being too large
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
|
||||
import net.minecraft.server.v1_15_R1.IRecipe;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutRecipeUpdate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
|
||||
@Override
|
||||
public List<Object> splitPackets(@NotNull final Object object,
|
||||
@NotNull final Player player) {
|
||||
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
|
||||
throw new IllegalArgumentException("Parameter not packet!");
|
||||
}
|
||||
|
||||
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
|
||||
List<IRecipe<?>> recipes = new ArrayList<>();
|
||||
try {
|
||||
Field f = oldPacket.getClass().getDeclaredField("a");
|
||||
f.setAccessible(true);
|
||||
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<Object> splitPackets = new ArrayList<>();
|
||||
List<IRecipe<?>> splitRecipes = new ArrayList<>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
splitRecipes.add(recipes.get(i));
|
||||
if (i % 100 == 0) {
|
||||
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
|
||||
splitPackets.add(newPacket);
|
||||
splitRecipes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return splitPackets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
|
||||
import net.minecraft.server.v1_16_R1.IRecipe;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutRecipeUpdate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
|
||||
@Override
|
||||
public List<Object> splitPackets(@NotNull final Object object,
|
||||
@NotNull final Player player) {
|
||||
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
|
||||
throw new IllegalArgumentException("Parameter not packet!");
|
||||
}
|
||||
|
||||
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
|
||||
List<IRecipe<?>> recipes = new ArrayList<>();
|
||||
try {
|
||||
Field f = oldPacket.getClass().getDeclaredField("a");
|
||||
f.setAccessible(true);
|
||||
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<Object> splitPackets = new ArrayList<>();
|
||||
List<IRecipe<?>> splitRecipes = new ArrayList<>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
splitRecipes.add(recipes.get(i));
|
||||
if (i % 100 == 0) {
|
||||
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
|
||||
splitPackets.add(newPacket);
|
||||
splitRecipes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return splitPackets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
|
||||
import net.minecraft.server.v1_16_R2.IRecipe;
|
||||
import net.minecraft.server.v1_16_R2.PacketPlayOutRecipeUpdate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
|
||||
@Override
|
||||
public List<Object> splitPackets(@NotNull final Object object,
|
||||
@NotNull final Player player) {
|
||||
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
|
||||
throw new IllegalArgumentException("Parameter not packet!");
|
||||
}
|
||||
|
||||
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
|
||||
List<IRecipe<?>> recipes = new ArrayList<>();
|
||||
try {
|
||||
Field f = oldPacket.getClass().getDeclaredField("a");
|
||||
f.setAccessible(true);
|
||||
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<Object> splitPackets = new ArrayList<>();
|
||||
List<IRecipe<?>> splitRecipes = new ArrayList<>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
splitRecipes.add(recipes.get(i));
|
||||
if (i % 100 == 0) {
|
||||
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
|
||||
splitPackets.add(newPacket);
|
||||
splitRecipes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return splitPackets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
|
||||
import net.minecraft.server.v1_16_R3.IRecipe;
|
||||
import net.minecraft.server.v1_16_R3.PacketPlayOutRecipeUpdate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
|
||||
@Override
|
||||
public List<Object> splitPackets(@NotNull final Object object,
|
||||
@NotNull final Player player) {
|
||||
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
|
||||
throw new IllegalArgumentException("Parameter not packet!");
|
||||
}
|
||||
|
||||
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
|
||||
List<IRecipe<?>> recipes = new ArrayList<>();
|
||||
try {
|
||||
Field f = oldPacket.getClass().getDeclaredField("a");
|
||||
f.setAccessible(true);
|
||||
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<Object> splitPackets = new ArrayList<>();
|
||||
List<IRecipe<?>> splitRecipes = new ArrayList<>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
splitRecipes.add(recipes.get(i));
|
||||
if (i % 100 == 0) {
|
||||
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
|
||||
splitPackets.add(newPacket);
|
||||
splitRecipes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return splitPackets;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.willfp.eco.spigot.display.packets.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.packets.PacketChat;
|
||||
import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant;
|
||||
@@ -57,6 +58,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketPlayOutRecipeUpdateFix(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketPlayOutRecipeUpdateFix extends PacketAdapter {
|
||||
/**
|
||||
* Create new fixer for PacketPlayOutRecipeUpdate.
|
||||
*
|
||||
* @param plugin Plugin.
|
||||
*/
|
||||
public PacketPlayOutRecipeUpdateFix(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.RECIPE_UPDATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(@NotNull final PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
List<Object> packets = InternalProxyUtils.getProxy(PacketPlayOutRecipeUpdateFixProxy.class).splitPackets(packet.getHandle(), player);
|
||||
if (packets.size() > 1) {
|
||||
event.setCancelled(true);
|
||||
for (Object o : packets) {
|
||||
PacketContainer container = PacketContainer.fromPacket(o);
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, container);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PacketPlayOutRecipeUpdateFixProxy extends AbstractProxy {
|
||||
/**
|
||||
* Split recipe update packet into smaller packets.
|
||||
*
|
||||
* @param object The packet.
|
||||
* @param player The player.
|
||||
* @return The packets, split up.
|
||||
*/
|
||||
List<Object> splitPackets(@NotNull Object object,
|
||||
@NotNull Player player);
|
||||
}
|
||||
Reference in New Issue
Block a user