2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync;
|
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
|
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;
|
|
|
|
|
2015-12-24 02:07:03 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-07-07 04:04:58 +02:00
|
|
|
import appeng.core.sync.packets.PacketAssemblerAnimation;
|
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;
|
2014-07-08 05:48:21 +02:00
|
|
|
import appeng.core.sync.packets.PacketCompressedNBT;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.sync.packets.PacketConfigButton;
|
2014-06-16 07:48:43 +02:00
|
|
|
import appeng.core.sync.packets.PacketCraftRequest;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2016-10-04 01:34:29 +02:00
|
|
|
import appeng.core.sync.packets.PacketJEIRecipe;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.core.sync.packets.PacketNewStorageDimension;
|
2014-07-21 05:45:08 +02:00
|
|
|
import appeng.core.sync.packets.PacketPaintedEntity;
|
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-04-17 06:38:43 +02:00
|
|
|
import appeng.core.sync.packets.PacketPatternSlot;
|
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
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public class AppEngPacketHandlerBase
|
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
private static final Map<Class<? extends AppEngPacket>, PacketTypes> REVERSE_LOOKUP = new HashMap<Class<? extends AppEngPacket>, AppEngPacketHandlerBase.PacketTypes>();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public enum PacketTypes
|
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_COMPASS_REQUEST( PacketCompassRequest.class ),
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_COMPASS_RESPONSE( PacketCompassResponse.class ),
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_INVENTORY_ACTION( PacketInventoryAction.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_ME_INVENTORY_UPDATE( PacketMEInventoryUpdate.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_CONFIG_BUTTON( PacketConfigButton.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_PART_PLACEMENT( PacketPartPlacement.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_LIGHTNING( PacketLightning.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_MATTER_CANNON( PacketMatterCannon.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_MOCK_EXPLOSION( PacketMockExplosion.class ),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_VALUE_CONFIG( PacketValueConfig.class ),
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_TRANSITION_EFFECT( PacketTransitionEffect.class ),
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_PROGRESS_VALUE( PacketProgressBar.class ),
|
2014-02-16 05:33:13 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_CLICK( PacketClick.class ),
|
2014-02-16 22:28:50 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_NEW_STORAGE_DIMENSION( PacketNewStorageDimension.class ),
|
2014-03-05 08:27:42 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_SWITCH_GUIS( PacketSwitchGuis.class ),
|
2014-03-30 00:36:37 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_SWAP_SLOTS( PacketSwapSlots.class ),
|
2014-04-17 06:38:43 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_PATTERN_SLOT( PacketPatternSlot.class ),
|
2014-05-03 21:12:19 +02:00
|
|
|
|
2016-10-04 01:34:29 +02:00
|
|
|
PACKET_RECIPE_JEI( PacketJEIRecipe.class ),
|
2014-05-13 06:11:19 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_PARTIAL_ITEM( PacketPartialItem.class ),
|
2014-06-16 07:48:43 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_CRAFTING_REQUEST( PacketCraftRequest.class ),
|
2014-07-07 04:04:58 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_ASSEMBLER_ANIMATION( PacketAssemblerAnimation.class ),
|
2014-07-08 05:48:21 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_COMPRESSED_NBT( PacketCompressedNBT.class ),
|
2014-07-21 05:45:08 +02:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
PACKET_PAINTED_ENTITY( PacketPaintedEntity.class );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
private final Class<? extends AppEngPacket> packetClass;
|
|
|
|
private final Constructor<? extends AppEngPacket> packetConstructor;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
PacketTypes( final Class<? extends AppEngPacket> c )
|
2015-03-23 16:36:06 +01:00
|
|
|
{
|
|
|
|
this.packetClass = c;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
Constructor<? extends AppEngPacket> x = null;
|
2013-12-27 23:59:59 +01:00
|
|
|
try
|
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
x = this.packetClass.getConstructor( ByteBuf.class );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final NoSuchMethodException ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final SecurityException ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
this.packetConstructor = x;
|
|
|
|
REVERSE_LOOKUP.put( this.packetClass, this );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-23 16:36:06 +01:00
|
|
|
if( this.packetConstructor == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Invalid Packet Class " + c + ", must be constructable on DataInputStream" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static PacketTypes getPacket( final int id )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
return ( values() )[id];
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
static PacketTypes getID( final Class<? extends AppEngPacket> c )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
return REVERSE_LOOKUP.get( c );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public AppEngPacket parsePacket( final ByteBuf in ) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-03-23 16:36:06 +01:00
|
|
|
return this.packetConstructor.newInstance( in );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|