Search in sources :

Example 1 with TargetContext

use of net.minecraftforge.server.permission.context.TargetContext in project EnderIO by SleepyTrousers.

the class TileKillerJoe method processTasks.

// TODO 1.11 check that broken tools can be removed by automation
@Override
protected boolean processTasks(boolean redstoneCheck) {
    updateArmSwingProgress();
    if (Prep.isValid(getWeapon()) != hasSword) {
        hasSword = Prep.isValid(getWeapon());
        forceUpdatePlayers();
    }
    if (tanksDirty && shouldDoWorkThisTick(20)) {
        PacketHandler.sendToAllAround(new PacketNutrientTank(this), this);
        tanksDirty = false;
    }
    if (!redstoneCheck) {
        return false;
    }
    if (tank.getFluidAmount() < getActivationAmount()) {
        return false;
    }
    if (!hasSword) {
        return false;
    }
    if (doMending()) {
        hooverXP();
        if (!needsMending()) {
            endMending();
        }
    }
    getAttackera().onUpdate();
    Attackera atackera = getAttackera();
    if (atackera.getTicksSinceLastSwing() < atackera.getCooldownPeriod()) {
        return false;
    }
    List<EntityLivingBase> entsInBounds = world.getEntitiesWithinAABB(EntityLivingBase.class, getKillBounds());
    for (EntityLivingBase ent : entsInBounds) {
        if (!ent.isDead && ent.deathTime <= 0 && !ent.isEntityInvulnerable(DamageSource.GENERIC) && ent.hurtResistantTime == 0) {
            if (ent instanceof EntityPlayer && ((EntityPlayer) ent).capabilities.disableDamage) {
                // Ignore players in creative, can't damage them;
                continue;
            }
            boolean togglePvp = false;
            if (ent instanceof EntityPlayer && !FMLCommonHandler.instance().getMinecraftServerInstance().isPVPEnabled()) {
                if (KillerJoeConfig.killerPvPoffDisablesSwing.get()) {
                    continue;
                } else if (KillerJoeConfig.killerPvPoffIsIgnored.get()) {
                    togglePvp = true;
                }
            }
            if (KillerJoeConfig.killerJoeMustSee.get() && !canJoeSee(ent)) {
                continue;
            }
            if (!PermissionAPI.hasPermission(getOwner().getAsGameProfile(), BlockKillerJoe.permissionAttacking, new TargetContext(atackera, ent))) {
                continue;
            }
            if (ent instanceof EntityZombie) {
                // TODO: tag the entity instead (see Powered Spawner)
                ZombieCache.cache.add(ent.getUniqueID());
            }
            try {
                if (togglePvp) {
                    FMLCommonHandler.instance().getMinecraftServerInstance().setAllowPvp(true);
                }
                atackera.attackTargetEntityWithCurrentItem(ent);
            } finally {
                if (togglePvp) {
                    FMLCommonHandler.instance().getMinecraftServerInstance().setAllowPvp(false);
                }
            }
            atackera.resetCooldown();
            useNutrient();
            swingWeapon();
            return false;
        }
    }
    return false;
}
Also used : PacketNutrientTank(crazypants.enderio.machines.machine.generator.zombie.PacketNutrientTank) EntityZombie(net.minecraft.entity.monster.EntityZombie) TargetContext(net.minecraftforge.server.permission.context.TargetContext) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with TargetContext

use of net.minecraftforge.server.permission.context.TargetContext in project EnderIO by SleepyTrousers.

the class ItemSoulVial method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack item, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
    if (entity.world.isRemote) {
        return false;
    }
    boolean isCreative = player.capabilities.isCreativeMode;
    if (CapturedMob.containsSoul(item) && !isCreative) {
        return false;
    }
    // first check if that entity can be picked up at all
    CapturedMob capturedMob = CapturedMob.create(entity);
    if (capturedMob == null) {
        if (entity instanceof EntityPlayer) {
            player.sendMessage(Lang.SOUL_VIAL_DENIED_PLAYER.toChatServer());
        } else if (CapturedMob.isBlacklisted(entity)) {
            player.sendMessage(Lang.SOUL_VIAL_DENIED_AALISTED.toChatServer());
        }
        return false;
    }
    // then check for reasons this specific one cannot
    if (entity instanceof IEntityOwnable && ((IEntityOwnable) entity).getOwnerId() != null && !player.equals(((IEntityOwnable) entity).getOwner()) && !PermissionAPI.hasPermission(player.getGameProfile(), permissionPickupOwned, new TargetContext(player, entity))) {
        player.sendMessage(Lang.SOUL_VIAL_DENIED_OWNED_PET.toChatServer());
        return false;
    }
    if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPickup, new TargetContext(player, entity))) {
        player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
        return false;
    }
    ItemStack capturedMobVessel = capturedMob.toStack(this, 1, 1);
    player.swingArm(hand);
    if (!isCreative) {
        entity.setDead();
        if (entity.isDead) {
            // So we do not shrink the stack when it is 1.
            if (item.getCount() > 1) {
                item.shrink(1);
                // Since this stack still exists, add the new vial to the first location, or drop
                if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
                    player.dropItem(capturedMobVessel, false);
                }
            } else {
                // Otherwise, just replace the stack
                player.setHeldItem(hand, capturedMobVessel);
            }
            player.inventoryContainer.detectAndSendChanges();
            return true;
        }
    } else {
        if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
            player.dropItem(capturedMobVessel, false);
        }
        player.inventoryContainer.detectAndSendChanges();
        return true;
    }
    return false;
}
Also used : CapturedMob(crazypants.enderio.util.CapturedMob) TargetContext(net.minecraftforge.server.permission.context.TargetContext) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IEntityOwnable(net.minecraft.entity.IEntityOwnable) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TargetContext (net.minecraftforge.server.permission.context.TargetContext)2 PacketNutrientTank (crazypants.enderio.machines.machine.generator.zombie.PacketNutrientTank)1 CapturedMob (crazypants.enderio.util.CapturedMob)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 IEntityOwnable (net.minecraft.entity.IEntityOwnable)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 ItemStack (net.minecraft.item.ItemStack)1