Search in sources :

Example 56 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class EntityMinecartAbstract method attack.

@Override
public boolean attack(EntityDamageEvent source) {
    if (invulnerable) {
        return false;
    } else {
        Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
        boolean instantKill = damager instanceof Player && ((Player) damager).isCreative();
        if (!instantKill)
            performHurtAnimation((int) source.getFinalDamage());
        if (instantKill || getDamage() > 40) {
            if (linkedEntity != null) {
                mountEntity(linkedEntity);
            }
            if (instantKill && (!hasCustomName())) {
                kill();
            } else {
                if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
                    dropItem();
                }
                close();
            }
        }
    }
    return true;
}
Also used : Entity(cn.nukkit.entity.Entity) Player(cn.nukkit.Player) EntityDamageByEntityEvent(cn.nukkit.event.entity.EntityDamageByEntityEvent)

Example 57 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class Effect method add.

public void add(Entity entity, boolean modify) {
    if (entity instanceof Player) {
        MobEffectPacket pk = new MobEffectPacket();
        pk.eid = entity.getId();
        pk.effectId = this.getId();
        pk.amplifier = this.getAmplifier();
        pk.particles = this.isVisible();
        pk.duration = this.getDuration();
        if (modify) {
            pk.eventId = MobEffectPacket.EVENT_MODIFY;
        } else {
            pk.eventId = MobEffectPacket.EVENT_ADD;
        }
        ((Player) entity).dataPacket(pk);
        if (this.id == Effect.SPEED) {
            ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1));
        }
        if (this.id == Effect.SLOWNESS) {
            ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1));
        }
    }
    if (this.id == Effect.INVISIBILITY) {
        entity.setDataFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_INVISIBLE, true);
        entity.setNameTagVisible(false);
    }
    if (this.id == Effect.ABSORPTION) {
        int add = (this.amplifier + 1) * 4;
        if (add > entity.getAbsorption())
            entity.setAbsorption(add);
    }
}
Also used : Player(cn.nukkit.Player) MobEffectPacket(cn.nukkit.network.protocol.MobEffectPacket)

Example 58 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class EntityHuman method initEntity.

@Override
protected void initEntity() {
    this.setDataFlag(DATA_PLAYER_FLAGS, DATA_PLAYER_FLAG_SLEEP, false);
    this.setDataFlag(DATA_FLAGS, DATA_FLAG_GRAVITY);
    this.setDataProperty(new IntPositionEntityData(DATA_PLAYER_BED_POSITION, 0, 0, 0), false);
    if (!(this instanceof Player)) {
        if (this.namedTag.contains("NameTag")) {
            this.setNameTag(this.namedTag.getString("NameTag"));
        }
        if (this.namedTag.contains("Skin") && this.namedTag.get("Skin") instanceof CompoundTag) {
            if (!this.namedTag.getCompound("Skin").contains("Transparent")) {
                this.namedTag.getCompound("Skin").putBoolean("Transparent", false);
            }
            this.setSkin(new Skin(this.namedTag.getCompound("Skin").getByteArray("Data"), this.namedTag.getCompound("Skin").getString("ModelId")));
        }
        this.uuid = Utils.dataToUUID(String.valueOf(this.getId()).getBytes(StandardCharsets.UTF_8), this.getSkin().getData(), this.getNameTag().getBytes(StandardCharsets.UTF_8));
    }
    super.initEntity();
}
Also used : Player(cn.nukkit.Player) IntPositionEntityData(cn.nukkit.entity.data.IntPositionEntityData) Skin(cn.nukkit.entity.data.Skin) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 59 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class EntityLiving method attack.

@Override
public boolean attack(EntityDamageEvent source) {
    if (this.attackTime > 0 || this.noDamageTicks > 0) {
        EntityDamageEvent lastCause = this.getLastDamageCause();
        if (lastCause != null && lastCause.getDamage() >= source.getDamage()) {
            return false;
        }
    }
    if (super.attack(source)) {
        if (source instanceof EntityDamageByEntityEvent) {
            Entity e = ((EntityDamageByEntityEvent) source).getDamager();
            if (source instanceof EntityDamageByChildEntityEvent) {
                e = ((EntityDamageByChildEntityEvent) source).getChild();
            }
            if (e.isOnFire() && !(e instanceof Player)) {
                this.setOnFire(2 * this.server.getDifficulty());
            }
            double deltaX = this.x - e.x;
            double deltaZ = this.z - e.z;
            this.knockBack(e, source.getDamage(), deltaX, deltaZ, ((EntityDamageByEntityEvent) source).getKnockBack());
        }
        EntityEventPacket pk = new EntityEventPacket();
        pk.eid = this.getId();
        pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION;
        Server.broadcastPacket(this.hasSpawned.values(), pk);
        this.attackTime = 10;
        return true;
    } else {
        return false;
    }
}
Also used : Player(cn.nukkit.Player) EntityEventPacket(cn.nukkit.network.protocol.EntityEventPacket)

Example 60 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class SayCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    String senderString;
    if (sender instanceof Player) {
        senderString = ((Player) sender).getDisplayName();
    } else if (sender instanceof ConsoleCommandSender) {
        senderString = "Server";
    } else {
        senderString = sender.getName();
    }
    String msg = "";
    for (String arg : args) {
        msg += arg + " ";
    }
    if (msg.length() > 0) {
        msg = msg.substring(0, msg.length() - 1);
    }
    sender.getServer().broadcastMessage(new TranslationContainer(TextFormat.LIGHT_PURPLE + "%chat.type.announcement", new String[] { senderString, TextFormat.LIGHT_PURPLE + msg }));
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) ConsoleCommandSender(cn.nukkit.command.ConsoleCommandSender)

Aggregations

Player (cn.nukkit.Player)85 TranslationContainer (cn.nukkit.lang.TranslationContainer)24 Entity (cn.nukkit.entity.Entity)13 BlockEntity (cn.nukkit.blockentity.BlockEntity)10 Item (cn.nukkit.item.Item)10 Level (cn.nukkit.level.Level)7 IOException (java.io.IOException)6 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)5 Block (cn.nukkit.block.Block)4 ItemBlock (cn.nukkit.item.ItemBlock)4 BlockAir (cn.nukkit.block.BlockAir)3 EventHandler (cn.nukkit.event.EventHandler)3 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)3 InventoryContentPacket (cn.nukkit.network.protocol.InventoryContentPacket)3 InventorySlotPacket (cn.nukkit.network.protocol.InventorySlotPacket)3 User (me.lucko.luckperms.common.model.User)3 IPlayer (cn.nukkit.IPlayer)2 CommandSender (cn.nukkit.command.CommandSender)2 EntityItem (cn.nukkit.entity.item.EntityItem)2 EntityArrow (cn.nukkit.entity.projectile.EntityArrow)2