2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2014-02-16 22:28:50 +01:00
|
|
|
import appeng.core.sync.packets.PacketClick;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.core.sync.packets.PacketCompassRequest;
|
|
|
|
import appeng.core.sync.packets.PacketCompassResponse;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.sync.packets.PacketConfigButton;
|
|
|
|
import appeng.core.sync.packets.PacketInventoryAction;
|
|
|
|
import appeng.core.sync.packets.PacketLightning;
|
|
|
|
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
|
|
|
import appeng.core.sync.packets.PacketMatterCannon;
|
|
|
|
import appeng.core.sync.packets.PacketMockExplosion;
|
|
|
|
import appeng.core.sync.packets.PacketMultiPart;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.core.sync.packets.PacketNEIRecipe;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.core.sync.packets.PacketNewStorageDimension;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.sync.packets.PacketPartPlacement;
|
2014-05-13 06:11:19 +02:00
|
|
|
import appeng.core.sync.packets.PacketPartialItem;
|
2014-02-16 05:33:13 +01:00
|
|
|
import appeng.core.sync.packets.PacketProgressBar;
|
2014-03-30 00:36:37 +01:00
|
|
|
import appeng.core.sync.packets.PacketSwapSlots;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.core.sync.packets.PacketSwitchGuis;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.core.sync.packets.PacketTransitionEffect;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class AppEngPacketHandlerBase
|
|
|
|
{
|
|
|
|
|
|
|
|
public static Map<Class, PacketTypes> reverseLookup = new HashMap<Class, AppEngPacketHandlerBase.PacketTypes>();
|
|
|
|
|
|
|
|
public enum PacketTypes
|
|
|
|
{
|
2014-03-02 09:35:11 +01:00
|
|
|
PACKET_COMPASS_REQUEST(PacketCompassRequest.class),
|
|
|
|
|
|
|
|
PACKET_COMPASS_RESPONSE(PacketCompassResponse.class),
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
PACKET_INVENTORY_ACTION(PacketInventoryAction.class),
|
|
|
|
|
|
|
|
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class),
|
|
|
|
|
|
|
|
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
|
|
|
|
|
|
|
|
PACKET_MULTIPART(PacketMultiPart.class),
|
|
|
|
|
|
|
|
PACKET_PARTPLACEMENT(PacketPartPlacement.class),
|
|
|
|
|
|
|
|
PACKET_LIGHTNING(PacketLightning.class),
|
|
|
|
|
|
|
|
PACKET_MATTERCANNON(PacketMatterCannon.class),
|
|
|
|
|
|
|
|
PACKET_MOCKEXPLOSION(PacketMockExplosion.class),
|
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
PACKET_VALUE_CONFIG(PacketValueConfig.class),
|
|
|
|
|
2014-02-14 05:27:15 +01:00
|
|
|
PACKET_TRANSITION_EFFECT(PacketTransitionEffect.class),
|
|
|
|
|
2014-02-16 05:33:13 +01:00
|
|
|
PACKET_PROGRESS_VALUE(PacketProgressBar.class),
|
|
|
|
|
2014-02-16 22:28:50 +01:00
|
|
|
PACKET_CLICK(PacketClick.class),
|
|
|
|
|
2014-03-05 08:27:42 +01:00
|
|
|
PACKET_NEW_STORAGE_DIMENSION(PacketNewStorageDimension.class),
|
|
|
|
|
2014-03-30 00:36:37 +01:00
|
|
|
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
|
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
PACKET_SWAP_SLOTS(PacketSwapSlots.class),
|
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
PACKET_RECIPE_NEI(PacketNEIRecipe.class),
|
|
|
|
|
|
|
|
PACKET_PARTIAL_ITEM(PacketPartialItem.class);
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
final public Class pc;
|
|
|
|
final public Constructor con;
|
|
|
|
|
|
|
|
private PacketTypes(Class c) {
|
|
|
|
pc = c;
|
|
|
|
|
|
|
|
Constructor x = null;
|
|
|
|
try
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
x = pc.getConstructor( ByteBuf.class );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (NoSuchMethodException e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch (SecurityException e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
con = x;
|
|
|
|
AppEngPacketHandlerBase.reverseLookup.put( pc, this );
|
|
|
|
|
|
|
|
if ( con == null )
|
|
|
|
throw new RuntimeException( "Invalid Packet Class, must be constructable on DataInputStream" );
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public AppEngPacket parsePacket(ByteBuf in) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return (AppEngPacket) con.newInstance( in );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PacketTypes getPacket(int id)
|
|
|
|
{
|
|
|
|
return (values())[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PacketTypes getID(Class<? extends AppEngPacket> c)
|
|
|
|
{
|
|
|
|
return AppEngPacketHandlerBase.reverseLookup.get( c );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|