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