Search in sources :

Example 26 with EntityPlayer

use of net.minecraft.server.v1_4_R1.EntityPlayer in project Citizens2 by CitizensDev.

the class PlayerAnimationImpl method play.

public static void play(PlayerAnimation animation, Player bplayer, int radius) {
    // TODO: this is pretty gross
    final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
    if (DEFAULTS.containsKey(animation)) {
        playDefaultAnimation(player, radius, DEFAULTS.get(animation));
        return;
    }
    switch(animation) {
        case SIT:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
            final NPC holder = CitizensAPI.getNPCRegistry().createNPC(EntityType.ARMOR_STAND, "");
            holder.spawn(player.getBukkitEntity().getLocation());
            ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
            trait.setGravity(false);
            trait.setHasArms(false);
            trait.setHasBaseplate(false);
            trait.setSmall(true);
            trait.setMarker(true);
            trait.setVisible(false);
            holder.getTrait(ArmorStandTrait.class).setVisible(false);
            holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
            holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
            new BukkitRunnable() {

                @Override
                public void cancel() {
                    super.cancel();
                    holder.destroy();
                }

                @Override
                public void run() {
                    if (player.dead || !player.valid || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
                        cancel();
                        return;
                    }
                    if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
                        cancel();
                        return;
                    }
                    if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
                        NMS.mount(holder.getEntity(), player.getBukkitEntity());
                    }
                }
            }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
            break;
        case SLEEP:
            PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
            sendPacketNearby(packet, player, radius);
            break;
        case SNEAK:
            player.getBukkitEntity().setSneaking(true);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_USE_MAINHAND_ITEM:
            player.c(EnumHand.MAIN_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_USE_OFFHAND_ITEM:
            player.c(EnumHand.OFF_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_SITTING:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
            NMS.mount(player.getBukkitEntity(), null);
            break;
        case STOP_SLEEPING:
            playDefaultAnimation(player, radius, 2);
            break;
        case STOP_SNEAKING:
            player.getBukkitEntity().setSneaking(false);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_USE_ITEM:
            player.clearActiveItem();
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BlockPosition(net.minecraft.server.v1_11_R1.BlockPosition) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) PacketPlayOutEntityMetadata(net.minecraft.server.v1_11_R1.PacketPlayOutEntityMetadata) EntityPlayer(net.minecraft.server.v1_11_R1.EntityPlayer) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) PacketPlayOutBed(net.minecraft.server.v1_11_R1.PacketPlayOutBed)

Example 27 with EntityPlayer

use of net.minecraft.server.v1_4_R1.EntityPlayer in project Citizens2 by CitizensDev.

the class CitizensBlockBreaker method run.

@Override
public BehaviorStatus run() {
    if (entity.dead) {
        return BehaviorStatus.FAILURE;
    }
    if (!isDigging) {
        return BehaviorStatus.SUCCESS;
    }
    // CraftBukkit
    currentTick = (int) (System.currentTimeMillis() / 50);
    if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
        startDigTick = currentTick;
        if (entity instanceof NPCHolder) {
            NPC npc = ((NPCHolder) entity).getNPC();
            if (npc != null && !npc.getNavigator().isNavigating()) {
                npc.getNavigator().setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
            }
        }
        return BehaviorStatus.RUNNING;
    }
    Util.faceLocation(entity.getBukkitEntity(), location);
    if (entity instanceof EntityPlayer) {
        PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
    }
    IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
    if (block == null || block == Blocks.AIR) {
        return BehaviorStatus.SUCCESS;
    } else {
        int tickDifference = currentTick - startDigTick;
        float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
        if (damage >= 1F) {
            entity.world.getWorld().getBlockAt(x, y, z).breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
            return BehaviorStatus.SUCCESS;
        }
        int modifiedDamage = (int) (damage * 10.0F);
        if (modifiedDamage != currentDamage) {
            setBlockDamage(modifiedDamage);
            currentDamage = modifiedDamage;
        }
    }
    return BehaviorStatus.RUNNING;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) IBlockData(net.minecraft.server.v1_11_R1.IBlockData) BlockPosition(net.minecraft.server.v1_11_R1.BlockPosition) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityPlayer(net.minecraft.server.v1_11_R1.EntityPlayer)

Example 28 with EntityPlayer

use of net.minecraft.server.v1_4_R1.EntityPlayer in project NoCheatPlus by NoCheatPlus.

the class MCAccessCB3100 method setDead.

@Override
public void setDead(final Player player, final int deathTicks) {
    final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
    mcPlayer.deathTicks = deathTicks;
    mcPlayer.dead = true;
}
Also used : EntityPlayer(net.minecraft.server.v1_7_R4.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer)

Example 29 with EntityPlayer

use of net.minecraft.server.v1_4_R1.EntityPlayer in project NoCheatPlus by NoCheatPlus.

the class MCAccessCB3100 method isIllegalBounds.

@Override
public AlmostBoolean isIllegalBounds(final Player player) {
    final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    if (entityPlayer.dead) {
        return AlmostBoolean.NO;
    }
    // TODO: Does this need a method call for the "real" box? Might be no problem during moving events, though.
    final AxisAlignedBB box = entityPlayer.boundingBox;
    if (LocUtil.isBadCoordinate(box.a, box.b, box.c, box.d, box.e, box.f)) {
        return AlmostBoolean.YES;
    }
    if (!entityPlayer.isSleeping()) {
        // This can not really test stance but height of bounding box.
        final double dY = Math.abs(box.e - box.b);
        if (dY > 1.8) {
            // dY > 1.65D ||
            return AlmostBoolean.YES;
        }
        if (dY < 0.1D && entityPlayer.length >= 0.1) {
            return AlmostBoolean.YES;
        }
    }
    return AlmostBoolean.MAYBE;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_7_R4.AxisAlignedBB) EntityPlayer(net.minecraft.server.v1_7_R4.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer)

Example 30 with EntityPlayer

use of net.minecraft.server.v1_4_R1.EntityPlayer in project NoCheatPlus by NoCheatPlus.

the class MCAccessCBDev method setDead.

@Override
public void setDead(final Player player, final int deathTicks) {
    final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
    mcPlayer.deathTicks = deathTicks;
    mcPlayer.dead = true;
}
Also used : EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)

Aggregations

Player (org.bukkit.entity.Player)17 EntityPlayer (net.minecraft.server.v1_8_R3.EntityPlayer)14 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)12 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)12 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)12 MyPet (de.Keyle.MyPet.api.entity.MyPet)9 Behavior (de.Keyle.MyPet.skill.skills.Behavior)9 NPC (net.citizensnpcs.api.npc.NPC)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)8 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)8 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)8 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)5 UUID (java.util.UUID)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)4 EntityPlayer (net.minecraft.server.v1_9_R2.EntityPlayer)4 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)4 ArmorStandTrait (net.citizensnpcs.trait.ArmorStandTrait)3