Search in sources :

Example 1 with Turtle

use of org.bukkit.entity.Turtle in project StackMob-2 by Nathat23.

the class ItemDrop method onEggDrop.

@EventHandler
public void onEggDrop(ItemSpawnEvent event) {
    switch(event.getEntity().getItemStack().getType()) {
        case EGG:
            // Metadata doesn't work because this event is fired before the metadata would be set.
            if (event.getEntity().getItemStack().containsEnchantment(Enchantment.DIG_SPEED)) {
                event.getEntity().getItemStack().removeEnchantment(Enchantment.DIG_SPEED);
                return;
            }
            for (Entity e : event.getEntity().getNearbyEntities(0.2, 0.3, 0.2)) {
                if (e instanceof Chicken && StackTools.hasSizeMoreThanOne(e)) {
                    int stackSize = StackTools.getSize(e);
                    int dropAmount = (int) Math.round(stackSize * ((ThreadLocalRandom.current().nextDouble(0.5) + 0.35)));
                    sm.getDropTools().dropEggs(event.getEntity().getItemStack(), dropAmount, e.getLocation());
                    break;
                }
            }
            break;
        case SCUTE:
            // Metadata doesn't work because this event is fired before the metadata would be set.
            if (event.getEntity().getItemStack().containsEnchantment(Enchantment.DIG_SPEED)) {
                event.getEntity().getItemStack().removeEnchantment(Enchantment.DIG_SPEED);
                return;
            }
            for (Entity e : event.getEntity().getNearbyEntities(1.0, 1.0, 1.0)) {
                if (e instanceof Turtle && ((Turtle) e).getAge() == 0 && StackTools.hasSizeMoreThanOne(e)) {
                    int stackSize = StackTools.getSize(e);
                    int dropAmount = (int) Math.round(stackSize * ((ThreadLocalRandom.current().nextDouble(0.5) + 0.35)));
                    sm.getDropTools().dropEggs(event.getEntity().getItemStack(), dropAmount, e.getLocation());
                    break;
                }
            }
            break;
        default:
            // Nothing to do, without it's considered as a bug by CodeFactor.
            break;
    }
}
Also used : Entity(org.bukkit.entity.Entity) Turtle(org.bukkit.entity.Turtle) Chicken(org.bukkit.entity.Chicken) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Turtle

use of org.bukkit.entity.Turtle in project RoseStacker by Rosewood-Development.

the class EntityStackSettings method canStackWith.

/**
 * Checks if one StackedEntity can stack with another and returns the comparison result
 *
 * @param stack1 The first stack
 * @param stack2 The second stack
 * @param comparingForUnstack true if the comparison is being made for unstacking, false otherwise
 * @param ignorePositions true if position checks for the entities should be ignored, false otherwise
 * @return the comparison result
 */
public EntityStackComparisonResult canStackWith(StackedEntity stack1, StackedEntity stack2, boolean comparingForUnstack, boolean ignorePositions) {
    LivingEntity entity1 = stack1.getEntity();
    LivingEntity entity2 = stack2.getEntity();
    if (entity1.getType() != entity2.getType())
        return EntityStackComparisonResult.DIFFERENT_ENTITY_TYPES;
    if (!this.enabled)
        return EntityStackComparisonResult.STACKING_NOT_ENABLED;
    int offset = comparingForUnstack ? -1 : 0;
    if (stack1.getStackSize() + stack2.getStackSize() + offset > this.getMaxStackSize())
        return EntityStackComparisonResult.STACK_SIZE_TOO_LARGE;
    if (PersistentDataUtils.isUnstackable(entity1) || PersistentDataUtils.isUnstackable(entity2))
        return EntityStackComparisonResult.MARKED_UNSTACKABLE;
    if (Setting.ENTITY_DONT_STACK_CUSTOM_NAMED.getBoolean() && (entity1.getCustomName() != null || entity2.getCustomName() != null))
        return EntityStackComparisonResult.CUSTOM_NAMED;
    if (!comparingForUnstack && !ignorePositions && !this.getEntityTypeData().isSwimmingMob() && !this.getEntityTypeData().isFlyingMob()) {
        if (Setting.ENTITY_ONLY_STACK_ON_GROUND.getBoolean() && (!entity1.isOnGround() || !entity2.isOnGround()))
            return EntityStackComparisonResult.NOT_ON_GROUND;
        if (Setting.ENTITY_DONT_STACK_IF_IN_WATER.getBoolean() && (entity1.getLocation().getBlock().getType() == Material.WATER || entity2.getLocation().getBlock().getType() == Material.WATER))
            return EntityStackComparisonResult.IN_WATER;
    }
    if (!comparingForUnstack && this.shouldOnlyStackFromSpawners() && (!PersistentDataUtils.isSpawnedFromSpawner(entity1) || !PersistentDataUtils.isSpawnedFromSpawner(entity2)))
        return EntityStackComparisonResult.NOT_SPAWNED_FROM_SPAWNER;
    // Don't stack if being ridden or is riding something
    if ((!entity1.getPassengers().isEmpty() || !entity2.getPassengers().isEmpty() || entity1.isInsideVehicle() || entity2.isInsideVehicle()) && !comparingForUnstack)
        // If comparing for unstack and is being ridden or is riding something, don't want to unstack it
        return EntityStackComparisonResult.PART_OF_VEHICLE;
    if (!comparingForUnstack && Setting.ENTITY_DONT_STACK_IF_LEASHED.getBoolean() && (entity1.isLeashed() || entity2.isLeashed()))
        return EntityStackComparisonResult.LEASHED;
    if (Setting.ENTITY_DONT_STACK_IF_INVULNERABLE.getBoolean() && (entity1.isInvulnerable() || entity2.isInvulnerable()))
        return EntityStackComparisonResult.INVULNERABLE;
    if (Setting.ENTITY_DONT_STACK_IF_HAS_EQUIPMENT.getBoolean()) {
        EntityEquipment equipment1 = entity1.getEquipment();
        EntityEquipment equipment2 = entity2.getEquipment();
        if (equipment1 != null)
            for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) if (equipment1.getItem(equipmentSlot).getType() != Material.AIR)
                return EntityStackComparisonResult.HAS_EQUIPMENT;
        if (equipment2 != null)
            for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) if (equipment2.getItem(equipmentSlot).getType() != Material.AIR)
                return EntityStackComparisonResult.HAS_EQUIPMENT;
    }
    if (this.isEntityColorable()) {
        Colorable colorable1 = (Colorable) entity1;
        Colorable colorable2 = (Colorable) entity2;
        if (this.dontStackIfDifferentColor && colorable1.getColor() != colorable2.getColor())
            return EntityStackComparisonResult.DIFFERENT_COLORS;
    }
    if (this.isEntitySittable()) {
        Sittable sittable1 = (Sittable) entity1;
        Sittable sittable2 = (Sittable) entity2;
        if (this.dontStackIfSitting && (sittable1.isSitting() || sittable2.isSitting()))
            return EntityStackComparisonResult.SITTING;
    }
    if (this.isEntityTameable()) {
        Tameable tameable1 = (Tameable) entity1;
        Tameable tameable2 = (Tameable) entity2;
        if (this.dontStackIfTamed && (tameable1.isTamed() || tameable2.isTamed()))
            return EntityStackComparisonResult.TAMED;
        if (this.dontStackIfDifferentOwners) {
            AnimalTamer tamer1 = tameable1.getOwner();
            AnimalTamer tamer2 = tameable2.getOwner();
            if (tamer1 != null && tamer2 != null && !tamer1.getUniqueId().equals(tamer2.getUniqueId()))
                return EntityStackComparisonResult.DIFFERENT_OWNERS;
        }
    }
    if (this.isEntityAnimals()) {
        Animals animals1 = (Animals) entity1;
        Animals animals2 = (Animals) entity2;
        NMSHandler nmsHandler = NMSAdapter.getHandler();
        boolean hasEgg = animals1.getType() == EntityType.TURTLE && (nmsHandler.isTurtlePregnant((Turtle) animals1) || nmsHandler.isTurtlePregnant((Turtle) animals2));
        if (this.dontStackIfBreeding && (animals1.isLoveMode() || animals2.isLoveMode() || (!animals1.canBreed() && animals1.isAdult()) || (!animals2.canBreed() && animals2.isAdult()) || hasEgg))
            return EntityStackComparisonResult.BREEDING;
    }
    if (this.isEntityAgeable()) {
        Ageable ageable1 = (Ageable) entity1;
        Ageable ageable2 = (Ageable) entity2;
        if (this.dontStackIfDifferentAge && ageable1.isAdult() != ageable2.isAdult())
            return EntityStackComparisonResult.DIFFERENT_AGES;
        if (this.dontStackIfBaby && (!ageable1.isAdult() || !ageable2.isAdult()))
            return EntityStackComparisonResult.BABY;
    }
    if (this.isEntityAbstractHorse()) {
        AbstractHorse abstractHorse1 = (AbstractHorse) entity1;
        AbstractHorse abstractHorse2 = (AbstractHorse) entity2;
        if (this.dontStackIfSaddled && (abstractHorse1.getInventory().getSaddle() != null || abstractHorse2.getInventory().getSaddle() != null))
            return EntityStackComparisonResult.SADDLED;
    }
    if (this.isEntityChestedHorse()) {
        ChestedHorse chestedHorse1 = (ChestedHorse) entity1;
        ChestedHorse chestedHorse2 = (ChestedHorse) entity2;
        if (this.dontStackIfChested && (chestedHorse1.isCarryingChest() || chestedHorse2.isCarryingChest()))
            return EntityStackComparisonResult.HAS_CHEST;
    }
    if (this.isEntityRaider()) {
        Raider raider1 = (Raider) entity1;
        Raider raider2 = (Raider) entity2;
        if (this.dontStackIfPatrolLeader && (raider1.isPatrolLeader() || raider2.isPatrolLeader()))
            return EntityStackComparisonResult.PATROL_LEADER;
        if (Setting.ENTITY_DONT_STACK_IF_ACTIVE_RAIDER.getBoolean() && (RaidListener.isActiveRaider(raider1) || RaidListener.isActiveRaider(raider2)))
            return EntityStackComparisonResult.PART_OF_ACTIVE_RAID;
    }
    if (this.isEntityMerchant()) {
        Merchant merchant1 = (Merchant) entity1;
        Merchant merchant2 = (Merchant) entity2;
        if (this.dontStackIfTrading && (merchant1.isTrading() || merchant2.isTrading()))
            return EntityStackComparisonResult.TRADING;
    }
    return this.canStackWithInternal(stack1, stack2);
}
Also used : Turtle(org.bukkit.entity.Turtle) AbstractHorse(org.bukkit.entity.AbstractHorse) Sittable(org.bukkit.entity.Sittable) Raider(org.bukkit.entity.Raider) Tameable(org.bukkit.entity.Tameable) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) Ageable(org.bukkit.entity.Ageable) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) Merchant(org.bukkit.inventory.Merchant) EntityEquipment(org.bukkit.inventory.EntityEquipment) ChestedHorse(org.bukkit.entity.ChestedHorse) Colorable(org.bukkit.material.Colorable) AnimalTamer(org.bukkit.entity.AnimalTamer)

Example 3 with Turtle

use of org.bukkit.entity.Turtle in project CoreProtect by PlayPro.

the class EntityChangeBlockListener method onEntityChangeBlock.

@EventHandler(priority = EventPriority.MONITOR)
protected void onEntityChangeBlock(EntityChangeBlockEvent event) {
    World world = event.getBlock().getWorld();
    if (!event.isCancelled() && Config.getConfig(world).ENTITY_CHANGE) {
        // Can be sand/gravel
        Entity entity = event.getEntity();
        Block block = event.getBlock();
        Material newtype = event.getTo();
        Material type = event.getBlock().getType();
        String e = "";
        if (entity instanceof Enderman) {
            e = "#enderman";
        } else if (entity instanceof EnderDragon) {
            e = "#enderdragon";
        } else if (entity instanceof Fox) {
            e = "#fox";
        } else if (entity instanceof Wither) {
            e = "#wither";
        } else if (entity instanceof Turtle) {
            e = "#turtle";
        } else if (entity instanceof Ravager) {
            e = "#ravager";
        } else if (entity instanceof Silverfish) {
            if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) {
                e = "#silverfish";
            }
        }
        if (e.length() > 0) {
            if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) {
                Queue.queueBlockBreak(e, block.getState(), type, block.getBlockData().getAsString(), 0);
            } else {
                queueBlockPlace(e, block.getState(), type, block.getState(), newtype, -1, 0, event.getBlockData().getAsString());
            }
        }
    }
}
Also used : Wither(org.bukkit.entity.Wither) Entity(org.bukkit.entity.Entity) Turtle(org.bukkit.entity.Turtle) EnderDragon(org.bukkit.entity.EnderDragon) Enderman(org.bukkit.entity.Enderman) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Silverfish(org.bukkit.entity.Silverfish) Ravager(org.bukkit.entity.Ravager) World(org.bukkit.World) Fox(org.bukkit.entity.Fox) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Turtle (org.bukkit.entity.Turtle)3 Entity (org.bukkit.entity.Entity)2 EventHandler (org.bukkit.event.EventHandler)2 NMSHandler (dev.rosewood.rosestacker.nms.NMSHandler)1 Material (org.bukkit.Material)1 World (org.bukkit.World)1 Block (org.bukkit.block.Block)1 AbstractHorse (org.bukkit.entity.AbstractHorse)1 Ageable (org.bukkit.entity.Ageable)1 AnimalTamer (org.bukkit.entity.AnimalTamer)1 Animals (org.bukkit.entity.Animals)1 ChestedHorse (org.bukkit.entity.ChestedHorse)1 Chicken (org.bukkit.entity.Chicken)1 EnderDragon (org.bukkit.entity.EnderDragon)1 Enderman (org.bukkit.entity.Enderman)1 Fox (org.bukkit.entity.Fox)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Raider (org.bukkit.entity.Raider)1 Ravager (org.bukkit.entity.Ravager)1 Silverfish (org.bukkit.entity.Silverfish)1