Search in sources :

Example 41 with EntityPlayer

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

the class MCAccessCB2882 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 (!entityPlayer.isSleeping()) {
        // This can not really test stance but height of bounding box.
        final double dY = Math.abs(box.e - box.b);
        // dY > 1.65D ||
        if (dY > 1.8)
            return AlmostBoolean.YES;
        if (dY < 0.1D && entityPlayer.length >= 0.1)
            return AlmostBoolean.YES;
    }
    return AlmostBoolean.MAYBE;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_6_R3.AxisAlignedBB) EntityPlayer(net.minecraft.server.v1_6_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer)

Example 42 with EntityPlayer

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

the class MCAccessSpigotCB1_9_R1 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.getBoundingBox();
    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_9_R1.AxisAlignedBB) EntityPlayer(net.minecraft.server.v1_9_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer)

Example 43 with EntityPlayer

use of net.minecraft.server.v1_16_R3.EntityPlayer in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method sendEntitySpawn.

@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
    CraftWorld world = ((CraftWorld) location.getWorld());
    net.minecraft.server.v1_16_R3.Entity nmsEntity;
    if (entityType.isCustom()) {
        if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
            org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
            for (Mechanism mechanism : mechanisms) {
                if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                    itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                }
            }
            nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
        } else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
            String name = null;
            String skin = null;
            for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
                if (mechanism.matches("name")) {
                    name = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                } else if (mechanism.matches("skin")) {
                    skin = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                }
                if (name != null && skin != null) {
                    break;
                }
            }
            nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
        } else {
            throw new IllegalArgumentException("entityType");
        }
    } else {
        nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
    }
    if (customUUID != null) {
        nmsEntity.e(customId);
        nmsEntity.a_(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.dead = false;
    FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
    fake.entity = new EntityTag(entity.getBukkitEntity());
    fake.entity.isFake = true;
    fake.entity.isFakeValid = true;
    List<TrackerData> trackers = new ArrayList<>();
    fake.triggerSpawnPacket = (player) -> {
        EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        PlayerConnection conn = nmsPlayer.playerConnection;
        final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
        tracker.b(nmsPlayer);
        final TrackerData data = new TrackerData();
        data.player = player;
        data.tracker = tracker;
        trackers.add(data);
        if (autoTrack) {
            new BukkitRunnable() {

                boolean wasOnline = true;

                @Override
                public void run() {
                    if (!fake.entity.isFakeValid) {
                        cancel();
                        return;
                    }
                    if (player.isOnline()) {
                        if (!wasOnline) {
                            tracker.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.a();
                    } else if (wasOnline) {
                        wasOnline = false;
                    }
                }
            }.runTaskTimer(Denizen.getInstance(), 1, 1);
        }
    };
    for (PlayerTag player : players) {
        fake.triggerSpawnPacket.accept(player);
    }
    fake.triggerUpdatePacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.a();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 44 with EntityPlayer

use of net.minecraft.server.v1_16_R3.EntityPlayer in project MyPet by xXKeyleXx.

the class ControlTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (controlPathfinderGoal == null) {
        if (petEntity.getPathfinder().hasGoal("Control")) {
            controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
        }
    }
    if (controlPathfinderGoal == null) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
        Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
        if (behaviorSkill.isActive()) {
            if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
                return false;
            }
        }
        for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
            if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
                if (entityLiving instanceof EntityPlayer) {
                    Player targetPlayer = (Player) entityLiving.getBukkitEntity();
                    if (myPet.getOwner().equals(targetPlayer)) {
                        continue;
                    } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
                        continue;
                    }
                } else if (entityLiving instanceof EntityTameableAnimal) {
                    EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
                    if (tameable.isTamed() && tameable.getOwner() != null) {
                        Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
                        if (myPet.getOwner().equals(tameableOwner)) {
                            continue;
                        } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
                            continue;
                        }
                    }
                } else if (entityLiving instanceof EntityMyPet) {
                    MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
                    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
                        continue;
                    }
                }
                if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
                    continue;
                }
                if (behaviorSkill != null) {
                    if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
                        if (entityLiving instanceof EntityTameableAnimal) {
                            continue;
                        } else if (entityLiving instanceof EntityMyPet) {
                            continue;
                        } else if (entityLiving instanceof EntityPlayer) {
                            continue;
                        }
                    }
                }
                controlPathfinderGoal.stopControl();
                this.target = entityLiving;
                return true;
            }
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_16_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet) EntityLiving(net.minecraft.server.v1_16_R1.EntityLiving) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_16_R1.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_16_R1.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_16_R1.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 45 with EntityPlayer

use of net.minecraft.server.v1_16_R3.EntityPlayer in project MyPet by xXKeyleXx.

the class ControlTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (controlPathfinderGoal == null) {
        if (petEntity.getPathfinder().hasGoal("Control")) {
            controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
        }
    }
    if (controlPathfinderGoal == null) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
        Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
        if (behaviorSkill.isActive()) {
            if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
                return false;
            }
        }
        for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow(this.range, 4.0D, this.range))) {
            if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
                if (entityLiving instanceof EntityPlayer) {
                    Player targetPlayer = (Player) entityLiving.getBukkitEntity();
                    if (myPet.getOwner().equals(targetPlayer)) {
                        continue;
                    } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
                        continue;
                    }
                } else if (entityLiving instanceof EntityTameableAnimal) {
                    EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
                    if (tameable.isTamed() && tameable.getOwner() != null) {
                        Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
                        if (myPet.getOwner().equals(tameableOwner)) {
                            continue;
                        } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
                            continue;
                        }
                    }
                } else if (entityLiving instanceof EntityMyPet) {
                    MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
                    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
                        continue;
                    }
                }
                if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
                    continue;
                }
                if (behaviorSkill != null) {
                    if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
                        if (entityLiving instanceof EntityTameableAnimal) {
                            continue;
                        } else if (entityLiving instanceof EntityMyPet) {
                            continue;
                        } else if (entityLiving instanceof EntityPlayer) {
                            continue;
                        }
                    }
                }
                controlPathfinderGoal.stopControl();
                this.target = entityLiving;
                return true;
            }
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_16_R3.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_16_R3.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Aggregations

Player (org.bukkit.entity.Player)26 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 EntityPlayer (net.minecraft.server.v1_8_R3.EntityPlayer)16 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)13 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)12 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)11 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)9 NPC (net.citizensnpcs.api.npc.NPC)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)8 Behavior (de.Keyle.MyPet.skill.skills.Behavior)6 EntityPlayer (net.minecraft.server.v1_9_R2.EntityPlayer)6 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)6 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)5 UUID (java.util.UUID)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)4