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;
}
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;
}
Aggregations