added protection against exceptions, for #1786
This commit is contained in:
parent
68205d0ca2
commit
92adc79f21
1 changed files with 38 additions and 11 deletions
|
@ -9,6 +9,7 @@
|
|||
package buildcraft;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.Packet;
|
||||
|
@ -19,29 +20,55 @@ import cpw.mods.fml.common.network.FMLOutboundHandler;
|
|||
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.core.network.BuildCraftPacket;
|
||||
|
||||
public class BuildCraftMod {
|
||||
public EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||
|
||||
|
||||
public void sendToPlayers(Packet packet, World world, int x, int y, int z, int maxDistance) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
try {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
} catch (Throwable t) {
|
||||
BCLog.logger.log(Level.WARNING, "sentToPlayers crash", t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendToPlayers(BuildCraftPacket packet, World world, int x, int y, int z, int maxDistance) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
try {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
} catch (Throwable t) {
|
||||
BCLog.logger.log(Level.WARNING, "sentToPlayers crash", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToPlayer(EntityPlayer entityplayer, BuildCraftPacket packet) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityplayer);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
try {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityplayer);
|
||||
channels.get(Side.SERVER).writeOutbound(packet);
|
||||
} catch (Throwable t) {
|
||||
String name = entityplayer.getDisplayName();
|
||||
|
||||
if (name == null) {
|
||||
name = "<no name>";
|
||||
}
|
||||
|
||||
BCLog.logger.log(Level.WARNING, "sentToPlayer \"" + name + "\" crash", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToServer(BuildCraftPacket packet) {
|
||||
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER);
|
||||
channels.get(Side.CLIENT).writeOutbound(packet);
|
||||
try {
|
||||
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER);
|
||||
channels.get(Side.CLIENT).writeOutbound(packet);
|
||||
} catch (Throwable t) {
|
||||
BCLog.logger.log(Level.WARNING, "sentToServer crash", t);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue