Search in sources :

Example 71 with Living

use of org.spongepowered.api.entity.living.Living in project Nucleus by NucleusPowered.

the class KillCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Collection<Entity> entities = args.getAll(key);
    int entityKillCount = 0;
    int playerKillCount = 0;
    for (Entity x : entities) {
        if (x instanceof Player) {
            Player pl = (Player) x;
            GameMode gm = pl.gameMode().getDirect().orElseGet(() -> pl.gameMode().getDefault());
            if (gm != GameModes.SURVIVAL && gm != GameModes.NOT_SET) {
                if (entities.size() == 1) {
                    throw ReturnMessageException.fromKey("command.kill.wronggm", pl.getName());
                } else {
                    continue;
                }
            }
        }
        DataTransactionResult dtr = x.offer(Keys.HEALTH, 0d);
        if (!dtr.isSuccessful() && !(x instanceof Living)) {
            x.remove();
        }
        entityKillCount++;
        if (x instanceof Player) {
            playerKillCount++;
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.killed", Nucleus.getNucleus().getNameUtil().getSerialisedName((Player) x)));
            ((Player) x).sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.killedby", src.getName()));
        }
    }
    if (entityKillCount > playerKillCount) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.overall", String.valueOf(entityKillCount), String.valueOf(playerKillCount)));
    }
    return CommandResult.success();
}
Also used : Entity(org.spongepowered.api.entity.Entity) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult)

Example 72 with Living

use of org.spongepowered.api.entity.living.Living in project Nucleus by NucleusPowered.

the class BackListeners method onDeathEvent.

@Listener
public void onDeathEvent(DestructEntityEvent.Death event) {
    Living e = event.getTargetEntity();
    if (!(e instanceof Player)) {
        return;
    }
    Player pl = (Player) e;
    if (backConfig.isOnDeath() && getLogBack(pl) && s.testSuffix(pl, ON_DEATH)) {
        handler.setLastLocation(pl, event.getTargetEntity().getTransform());
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Listener(org.spongepowered.api.event.Listener)

Aggregations

Living (org.spongepowered.api.entity.living.Living)72 Entity (org.spongepowered.api.entity.Entity)36 Player (org.spongepowered.api.entity.living.player.Player)18 Instruction (com.skelril.openboss.Instruction)15 Listener (org.spongepowered.api.event.Listener)14 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)13 World (org.spongepowered.api.world.World)12 NamedBindInstruction (com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction)10 HealthBindInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction)10 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)6 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)6 BackTeleportInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.BackTeleportInstruction)6 HealableInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealableInstruction)6 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)5