<commit_before>package net.gigimoi.zombietc.net;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import net.gigimoi.zombietc.ZombieTC;
import net.gigimoi.zombietc.entity.EntityZZombie;
import net.gigimoi.zombietc.event.PlayerManager;
import net.gigimoi.zombietc.item.weapon.ItemWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;

/**
 * Created by gigimoi on 7/17/2014.
 */
public class MessageShoot implements IMessage {
    public Entity shooter;
    public Entity hit;
    public Item weapon;

    public MessageShoot() {
    }

    public MessageShoot(Entity shooter, Entity hit, Item weapon) {
        this.shooter = shooter;
        this.weapon = weapon;
        this.hit = hit;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        shooter = ZombieTC.proxy.getWorld(Side.SERVER).getEntityByID(buf.readInt());
        hit = ZombieTC.proxy.getWorld(Side.SERVER).getEntityByID(buf.readInt());
        weapon = Item.getItemById(buf.readInt());
    }

    @Override
    public void toBytes(ByteBuf buf) {
        if (shooter != null) {
            buf.writeInt(shooter.getEntityId());
        } else {
            buf.writeInt(-1);
        }
        if (hit != null) {
            buf.writeInt(hit.getEntityId());
        } else {
            buf.writeInt(-1);
        }
        buf.writeInt(Item.getIdFromItem(weapon));
    }

    public static class MessageShootHandler implements IMessageHandler<MessageShoot, MessageShoot> {
        @Override
        public MessageShoot onMessage(MessageShoot message, MessageContext ctx) {
            World world = ((EntityLivingBase) message.shooter).worldObj;
            //TODO: Server side raytracing
            if (!message.hit.isDead) {
                if (message.hit != null && message.shooter != null) {
                    EntityPlayer player = null;
                    if (EntityPlayer.class.isAssignableFrom(message.shooter.getClass())) {
                        player = ZombieTC.proxy.getWorld(ctx.side).getPlayerEntityByName(message.shooter.getCommandSenderName());
                    }
                    if (player != null) {
                        PlayerManager.ZombieTCPlayerProperties.get(player).vim += 10;
                        if (EntityZZombie.class.isAssignableFrom(message.hit.getClass())) {
                            EntityZZombie zombie = (EntityZZombie) message.hit;
                            if(zombie.getHealth() > 0) {
                                ((ItemWeapon) message.weapon).bulletType.onHit(player, zombie);
                                if (zombie.getHealth() <= 0) {
                                    PlayerManager.ZombieTCPlayerProperties.get(player).vim += 40;
                                }
                            }
                        }
                        if (ctx.side == Side.SERVER) {
                            ZombieTC.network.sendToAll(message);
                        }
                    }
                }
            }
            return null;
        }
    }
}<commit_msg>Fixed double damage on integrated client.<commit_after>package net.gigimoi.zombietc.net;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import net.gigimoi.zombietc.ZombieTC;
import net.gigimoi.zombietc.entity.EntityZZombie;
import net.gigimoi.zombietc.event.PlayerManager;
import net.gigimoi.zombietc.item.weapon.ItemWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;

/**
 * Created by gigimoi on 7/17/2014.
 */
public class MessageShoot implements IMessage {
    public Entity shooter;
    public Entity hit;
    public Item weapon;

    public MessageShoot() {
    }

    public MessageShoot(Entity shooter, Entity hit, Item weapon) {
        this.shooter = shooter;
        this.weapon = weapon;
        this.hit = hit;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        shooter = ZombieTC.proxy.getWorld(Side.SERVER).getEntityByID(buf.readInt());
        hit = ZombieTC.proxy.getWorld(Side.SERVER).getEntityByID(buf.readInt());
        weapon = Item.getItemById(buf.readInt());
    }

    @Override
    public void toBytes(ByteBuf buf) {
        if (shooter != null) {
            buf.writeInt(shooter.getEntityId());
        } else {
            buf.writeInt(-1);
        }
        if (hit != null) {
            buf.writeInt(hit.getEntityId());
        } else {
            buf.writeInt(-1);
        }
        buf.writeInt(Item.getIdFromItem(weapon));
    }

    public static class MessageShootHandler implements IMessageHandler<MessageShoot, MessageShoot> {
        @Override
        public MessageShoot onMessage(MessageShoot message, MessageContext ctx) {
            World world = ((EntityLivingBase) message.shooter).worldObj;
            //TODO: Server side raytracing
            System.out.println(ctx.side.isServer());
            if(ctx.side.isClient() || (ctx.side.isServer() && ZombieTC.proxy.getPlayer() == null)) { //Do not run twice on integrated server
                if (!message.hit.isDead) {
                    if (message.hit != null && message.shooter != null) {
                        EntityPlayer player = null;
                        if (EntityPlayer.class.isAssignableFrom(message.shooter.getClass())) {
                            player = ZombieTC.proxy.getWorld(ctx.side).getPlayerEntityByName(message.shooter.getCommandSenderName());
                        }
                        if (player != null) {
                            PlayerManager.ZombieTCPlayerProperties.get(player).vim += 10;
                            if (EntityZZombie.class.isAssignableFrom(message.hit.getClass())) {
                                EntityZZombie zombie = (EntityZZombie) message.hit;
                                if (zombie.getHealth() > 0) {
                                    ((ItemWeapon) message.weapon).bulletType.onHit(player, zombie);
                                    if (zombie.getHealth() <= 0) {
                                        PlayerManager.ZombieTCPlayerProperties.get(player).vim += 40;
                                    } else {
                                    }
                                }
                            }
                            if (ctx.side == Side.SERVER) {
                                ZombieTC.network.sendToAll(message);
                            }
                        }
                    }
                }
            } else {
                if(ctx.side.isServer()) {
                    ZombieTC.network.sendToAll(message);
                }
            }
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.10415520088057237, 'fraction_numerical': 0.004127682993946065, 'mean_word_length': 1.7754868270332187, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1886353', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2024, 'n_words': 334}