Skip to content

Commit

Permalink
Remove IOException escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
bziemons committed May 18, 2016
1 parent b178cac commit 39a90b8
Show file tree
Hide file tree
Showing 161 changed files with 1,175 additions and 1,606 deletions.
6 changes: 2 additions & 4 deletions common/logisticspipes/blocks/stats/TrackingTask.java
@@ -1,7 +1,5 @@
package logisticspipes.blocks.stats;

import java.io.IOException;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

Expand Down Expand Up @@ -59,13 +57,13 @@ public void writeToNBT(NBTTagCompound nbt) {
item.makeNormalStack(1).writeToNBT(nbt);
}

public void writeToLPData(LPDataOutput output) throws IOException {
public void writeToLPData(LPDataOutput output) {
output.writeLongArray(amountRecorded);
output.writeInt(arrayPos);
output.writeItemIdentifier(item);
}

public void readFromLPData(LPDataInput input) throws IOException {
public void readFromLPData(LPDataInput input) {
amountRecorded = input.readLongArray();
arrayPos = input.readInt();
item = input.readItemIdentifier();
Expand Down
12 changes: 6 additions & 6 deletions common/logisticspipes/config/PlayerConfig.java
Expand Up @@ -55,10 +55,6 @@ public PlayerConfig(boolean uninitialised, PlayerIdentifier ident) {
playerIdent = ident;
}

public void setUseNewRenderer(boolean flag) {
useNewRenderer = flag;
}

public void setUseFallbackRenderer(boolean flag) {
useFallbackRenderer = flag;
}
Expand All @@ -75,14 +71,14 @@ public void sendUpdate() {
MainProxy.sendPacketToServer(PacketHandler.getPacket(PlayerConfigToServerPacket.class).setConfig(this));
}

public void writeData(LPDataOutput output) throws IOException {
public void writeData(LPDataOutput output) {
output.writeBoolean(useNewRenderer);
output.writeBoolean(useFallbackRenderer);
output.writeInt(renderPipeDistance);
output.writeInt(renderPipeContentDistance);
}

public void readData(LPDataInput input) throws IOException {
public void readData(LPDataInput input) {
useNewRenderer = input.readBoolean();
useFallbackRenderer = input.readBoolean();
renderPipeDistance = input.readInt();
Expand Down Expand Up @@ -218,4 +214,8 @@ public void applyTo(PlayerConfig playerConfig) {
public boolean isUseNewRenderer() {
return useNewRenderer && SimpleServiceLocator.cclProxy.isActivated();
}

public void setUseNewRenderer(boolean flag) {
useNewRenderer = flag;
}
}
6 changes: 2 additions & 4 deletions common/logisticspipes/interfaces/IClientState.java
@@ -1,13 +1,11 @@
package logisticspipes.interfaces;

import java.io.IOException;

import network.rs485.logisticspipes.util.LPDataInput;
import network.rs485.logisticspipes.util.LPDataOutput;

public interface IClientState {

void writeData(LPDataOutput output) throws IOException;
void writeData(LPDataOutput output);

void readData(LPDataInput input) throws IOException;
void readData(LPDataInput input);
}
4 changes: 1 addition & 3 deletions common/logisticspipes/network/IReadListObject.java
@@ -1,10 +1,8 @@
package logisticspipes.network;

import java.io.IOException;

import network.rs485.logisticspipes.util.LPDataInput;

public interface IReadListObject<T> {

T readObject(LPDataInput input) throws IOException;
T readObject(LPDataInput input);
}
4 changes: 1 addition & 3 deletions common/logisticspipes/network/IWriteListObject.java
@@ -1,10 +1,8 @@
package logisticspipes.network;

import java.io.IOException;

import network.rs485.logisticspipes.util.LPDataOutput;

public interface IWriteListObject<T> {

void writeObject(LPDataOutput output, T object) throws IOException;
void writeObject(LPDataOutput output, T object);
}
4 changes: 2 additions & 2 deletions common/logisticspipes/network/NewGuiHandler.java
Expand Up @@ -36,6 +36,8 @@ public class NewGuiHandler {
public static List<GuiProvider> guilist;
public static Map<Class<? extends GuiProvider>, GuiProvider> guimap;

private NewGuiHandler() { }

@SuppressWarnings("unchecked")
// Suppressed because this cast should never fail.
public static <T extends GuiProvider> T getGui(Class<T> clazz) {
Expand Down Expand Up @@ -64,7 +66,6 @@ public static final void initialize() {
}
}

@SneakyThrows(IOException.class)
public static void openGui(GuiProvider guiProvider, EntityPlayer oPlayer) {
if (!(oPlayer instanceof EntityPlayerMP)) {
throw new UnsupportedOperationException("Gui can only be opened on the server side");
Expand Down Expand Up @@ -96,7 +97,6 @@ public static void openGui(GuiProvider guiProvider, EntityPlayer oPlayer) {
player.openContainer.addCraftingToCrafters(player);
}

@SneakyThrows(IOException.class)
@SideOnly(Side.CLIENT)
public static void openGui(GUIPacket packet, EntityPlayer player) {
int guiID = packet.getGuiID();
Expand Down
100 changes: 49 additions & 51 deletions common/logisticspipes/network/PacketHandler.java
Expand Up @@ -39,11 +39,12 @@
@Sharable
public class PacketHandler extends MessageToMessageCodec<FMLProxyPacket, ModernPacket> {

public static final Map<Integer, StackTraceElement[]> debugMap = new HashMap<>();
//TODO correct to work with WeakReference (See FML original)
protected static final AttributeKey<ThreadLocal<FMLProxyPacket>> INBOUNDPACKETTRACKER = new AttributeKey<>("lp:inboundpacket");
public static List<ModernPacket> packetlist;
public static Map<Class<? extends ModernPacket>, ModernPacket> packetmap;

private static int packetDebugID = 1;
public static final Map<Integer, StackTraceElement[]> debugMap = new HashMap<>();

@SuppressWarnings("unchecked")
// Suppressed because this cast should never fail.
Expand All @@ -60,18 +61,6 @@ public static <T extends ModernPacket> T getPacket(Class<T> clazz) {
return packet;
}

//horrible hack to carry the proper player for the side along...
static class InboundModernPacketWrapper {

final ModernPacket packet;
final EntityPlayer player;

InboundModernPacketWrapper(ModernPacket p, EntityPlayer e) {
packet = p;
player = e;
}
}

/*
* enumerates all ModernPackets, sets their IDs and populate packetlist/packetmap
*/
Expand All @@ -97,15 +86,6 @@ public static final void initialize() {
}
}

//TODO correct to work with WeakReference (See FML original)
protected static final AttributeKey<ThreadLocal<FMLProxyPacket>> INBOUNDPACKETTRACKER = new AttributeKey<>("lp:inboundpacket");

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
super.handlerAdded(ctx);
ctx.attr(PacketHandler.INBOUNDPACKETTRACKER).set(new ThreadLocal<>());
}

//Used to provide the Description packet
public static FMLProxyPacket toFMLPacket(ModernPacket msg) throws Exception {
return PacketHandler.toFMLPacket(msg, MainProxy.networkChannelName);
Expand All @@ -121,6 +101,44 @@ private static FMLProxyPacket toFMLPacket(ModernPacket msg, String channel) thro
return new FMLProxyPacket(buffer, channel);
}

//hacky callback to process packets coming from by the packetbufferhandler decompressors
//TODO replace with proper netty implementation
public static void onPacketData(final LPDataInput data, final EntityPlayer player) {
if (player == null) {
return;
}
final int packetID = data.readShort();
final ModernPacket packet = PacketHandler.packetlist.get(packetID).template();
packet.setDebugId(data.readInt());
packet.readData(data);
PacketHandler.onPacketData(packet, player);
}

private static void onPacketData(ModernPacket packet, final EntityPlayer player) {
try {
packet.processPacket(player);
if (LPConstants.DEBUG) {
PacketHandler.debugMap.remove(packet.getDebugId());
}
} catch (DelayPacketException e) {
if (packet.retry() && MainProxy.isClient(player.getEntityWorld())) {
SimpleServiceLocator.clientBufferHandler.queueFailedPacket(packet, player);
} else if (LPConstants.DEBUG) {
LogisticsPipes.log.error(packet.getClass().getName());
LogisticsPipes.log.error(packet.toString());
e.printStackTrace();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
super.handlerAdded(ctx);
ctx.attr(PacketHandler.INBOUNDPACKETTRACKER).set(new ThreadLocal<>());
}

@Override
protected final void encode(ChannelHandlerContext ctx, ModernPacket msg, List<Object> out) throws Exception {
FMLProxyPacket proxy = PacketHandler.toFMLPacket(msg, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
Expand Down Expand Up @@ -150,35 +168,15 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
super.exceptionCaught(ctx, cause);
}

//hacky callback to process packets coming from by the packetbufferhandler decompressors
//TODO replace with proper netty implementation
public static void onPacketData(final LPDataInput data, final EntityPlayer player) throws IOException {
if (player == null) {
return;
}
final int packetID = data.readShort();
final ModernPacket packet = PacketHandler.packetlist.get(packetID).template();
packet.setDebugId(data.readInt());
packet.readData(data);
PacketHandler.onPacketData(packet, player);
}
//horrible hack to carry the proper player for the side along...
static class InboundModernPacketWrapper {

private static void onPacketData(ModernPacket packet, final EntityPlayer player) {
try {
packet.processPacket(player);
if (LPConstants.DEBUG) {
PacketHandler.debugMap.remove(packet.getDebugId());
}
} catch (DelayPacketException e) {
if (packet.retry() && MainProxy.isClient(player.getEntityWorld())) {
SimpleServiceLocator.clientBufferHandler.queueFailedPacket(packet, player);
} else if (LPConstants.DEBUG) {
LogisticsPipes.log.error(packet.getClass().getName());
LogisticsPipes.log.error(packet.toString());
e.printStackTrace();
}
} catch (Exception e) {
throw new RuntimeException(e);
final ModernPacket packet;
final EntityPlayer player;

InboundModernPacketWrapper(ModernPacket p, EntityPlayer e) {
packet = p;
player = e;
}
}
}
@@ -1,7 +1,5 @@
package logisticspipes.network.abstractguis;

import java.io.IOException;

import lombok.Getter;
import lombok.Setter;

Expand All @@ -10,22 +8,22 @@

public abstract class BooleanModuleCoordinatesGuiProvider extends ModuleCoordinatesGuiProvider {

public BooleanModuleCoordinatesGuiProvider(int id) {
super(id);
}

@Getter
@Setter
private boolean flag;

public BooleanModuleCoordinatesGuiProvider(int id) {
super(id);
}

@Override
public void writeData(LPDataOutput output) throws IOException {
public void writeData(LPDataOutput output) {
super.writeData(output);
output.writeBoolean(flag);
}

@Override
public void readData(LPDataInput input) throws IOException {
public void readData(LPDataInput input) {
super.readData(input);
flag = input.readBoolean();
}
Expand Down
@@ -1,7 +1,5 @@
package logisticspipes.network.abstractguis;

import java.io.IOException;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

Expand All @@ -18,10 +16,6 @@
@ToString
public abstract class CoordinatesGuiProvider extends GuiProvider {

public CoordinatesGuiProvider(int id) {
super(id);
}

@Getter
@Setter
private int posX;
Expand All @@ -32,16 +26,20 @@ public CoordinatesGuiProvider(int id) {
@Setter
private int posZ;

public CoordinatesGuiProvider(int id) {
super(id);
}

@Override
public void writeData(LPDataOutput output) throws IOException {
public void writeData(LPDataOutput output) {

output.writeInt(posX);
output.writeInt(posY);
output.writeInt(posZ);
}

@Override
public void readData(LPDataInput input) throws IOException {
public void readData(LPDataInput input) {

posX = input.readInt();
posY = input.readInt();
Expand Down
@@ -1,7 +1,5 @@
package logisticspipes.network.abstractguis;

import java.io.IOException;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

Expand All @@ -19,10 +17,6 @@
@ToString
public abstract class CoordinatesPopupGuiProvider extends PopupGuiProvider {

public CoordinatesPopupGuiProvider(int id) {
super(id);
}

@Getter
@Setter
private int posX;
Expand All @@ -33,16 +27,20 @@ public CoordinatesPopupGuiProvider(int id) {
@Setter
private int posZ;

public CoordinatesPopupGuiProvider(int id) {
super(id);
}

@Override
public void writeData(LPDataOutput output) throws IOException {
public void writeData(LPDataOutput output) {

output.writeInt(posX);
output.writeInt(posY);
output.writeInt(posZ);
}

@Override
public void readData(LPDataInput input) throws IOException {
public void readData(LPDataInput input) {

posX = input.readInt();
posY = input.readInt();
Expand Down

0 comments on commit 39a90b8

Please sign in to comment.