Java Code Examples for org.bukkit.entity.EntityType#ARMOR_STAND

The following examples show how to use org.bukkit.entity.EntityType#ARMOR_STAND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmorStandDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeDupe() {
    if (this.armorStand == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }
    boolean removed = false;
    for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.ARMOR_STAND) {
            continue;
        }
        ArmorStand eArmorStand = (ArmorStand) entity;

        if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId())) {
            if (DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {
                Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
Example 2
Source File: MagnetModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
public static boolean isDisplay(Entity entity) {
    try {
        if (entity.getType() == EntityType.DROPPED_ITEM) {
            ItemMeta itemMeta = ((Item) entity).getItemStack().getItemMeta();
            if (itemMeta != null && containsLocation(itemMeta.getDisplayName())) {
                return true;
            }
        } else if (entity.getType() == EntityType.ARMOR_STAND) {
            if (containsLocation(entity.getCustomName())) {
                return true;
            }
        }
    } catch (NoSuchFieldError error) {
        // do nothing
    }
    return false;
}
 
Example 3
Source File: ArmorStandListener.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler
public void armorStandStop(EntitySpawnEvent event)
{
    if(event.getEntityType() == EntityType.ARMOR_STAND)
        event.setCancelled(true);
}
 
Example 4
Source File: DeathStandsModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void on(EntityDamageEvent event) {
    if (event.getEntityType() != EntityType.ARMOR_STAND) return;

    if (!isProtectedArmourStand(event.getEntity())) return;

    // always cancel events, we choose when to break the stand
    event.setCancelled(true);

    final ArmorStand stand = (ArmorStand) event.getEntity();
    final Location loc = stand.getLocation();
    final World world = stand.getWorld();

    // for the first 2 seconds don't allow breaking
    // to avoid accidental breaks after kill
    if (event.getEntity().getTicksLived() < 2 * TICKS_PER_SECOND) {
        world.playEffect(stand.getEyeLocation(), Effect.WITCH_MAGIC, 0);
        return;
    }

    // drop each of it's worn items
    for (final ItemStack stack : Maps.filterValues(getItems(stand), Predicates.not(EMPTY_ITEM)).values()) {
        world.dropItemNaturally(loc, stack);
    }

    // kill the stand now
    stand.remove();
}
 
Example 5
Source File: SeismicAxe.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        List<Block> blocks = p.getLineOfSight(null, RANGE);

        for (int i = 2; i < blocks.size(); i++) {
            Block ground = findGround(blocks.get(i));
            Location groundLocation = ground.getLocation();

            ground.getWorld().playEffect(groundLocation, Effect.STEP_SOUND, ground.getType());

            if (ground.getRelative(BlockFace.UP).getType() == Material.AIR) {
                Location loc = ground.getRelative(BlockFace.UP).getLocation().add(0.5, 0.0, 0.5);
                FallingBlock block = ground.getWorld().spawnFallingBlock(loc, ground.getBlockData());
                block.setDropItem(false);
                block.setVelocity(new Vector(0, 0.4 + i * 0.01, 0));
                block.setMetadata("seismic_axe", new FixedMetadataValue(SlimefunPlugin.instance, "fake_block"));
            }

            for (Entity n : ground.getChunk().getEntities()) {
                if (n instanceof LivingEntity && n.getType() != EntityType.ARMOR_STAND && n.getLocation().distance(groundLocation) <= 2.0D && !n.getUniqueId().equals(p.getUniqueId())) {
                    pushEntity(p, n);
                }
            }
        }

        for (int i = 0; i < 4; i++) {
            damageItem(p, e.getItem());
        }
    };
}
 
Example 6
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityType getType() {
    return EntityType.ARMOR_STAND;
}
 
Example 7
Source File: Utils.java    From ShopChest with MIT License 4 votes vote down vote up
/**
 * Create a {@code PacketPlayOutSpawnEntity} object.
 * Only {@link EntityType#ARMOR_STAND} and {@link EntityType#DROPPED_ITEM} are supported! 
 */
public static Object createPacketSpawnEntity(ShopChest plugin, int id, UUID uuid, Location loc, EntityType type) {
    try {
        Class<?> packetClass = getNMSClass("PacketPlayOutSpawnEntity");
        Object packet = packetClass.getConstructor().newInstance();
        boolean isPre9 = getMajorVersion() < 9;
        boolean isPre14 = getMajorVersion() < 14;

        Field[] fields = new Field[12];
        fields[0] = packetClass.getDeclaredField("a"); // ID
        fields[1] = packetClass.getDeclaredField("b"); // UUID (Only 1.9+)
        fields[2] = packetClass.getDeclaredField(isPre9 ? "b" : "c"); // Loc X
        fields[3] = packetClass.getDeclaredField(isPre9 ? "c" : "d"); // Loc Y
        fields[4] = packetClass.getDeclaredField(isPre9 ? "d" : "e"); // Loc Z
        fields[5] = packetClass.getDeclaredField(isPre9 ? "e" : "f"); // Mot X
        fields[6] = packetClass.getDeclaredField(isPre9 ? "f" : "g"); // Mot Y
        fields[7] = packetClass.getDeclaredField(isPre9 ? "g" : "h"); // Mot Z
        fields[8] = packetClass.getDeclaredField(isPre9 ? "h" : "i"); // Pitch
        fields[9] = packetClass.getDeclaredField(isPre9 ? "i" : "j"); // Yaw
        fields[10] = packetClass.getDeclaredField(isPre9 ? "j" : "k"); // Type
        fields[11] = packetClass.getDeclaredField(isPre9 ? "k" : "l"); // Data

        for (Field field : fields) {
            field.setAccessible(true);
        }

        Object entityType = null;
        if (!isPre14) {
            Class<?> entityTypesClass = getNMSClass("EntityTypes");
            entityType = entityTypesClass.getField(type == EntityType.ARMOR_STAND ? "ARMOR_STAND" : "ITEM").get(null);
        }

        double y = loc.getY();
        if (type == EntityType.ARMOR_STAND && !getServerVersion().equals("v1_8_R1")) {
            // Marker armor stand => lift by normal armor stand height
            y += 1.975;
        }

        fields[0].set(packet, id);
        if (!isPre9) fields[1].set(packet, uuid);
        if (isPre9) {
            fields[2].set(packet, (int)(loc.getX() * 32));
            fields[3].set(packet, (int)(y * 32));
            fields[4].set(packet, (int)(loc.getZ() * 32));
        } else {
            fields[2].set(packet, loc.getX());
            fields[3].set(packet, y);
            fields[4].set(packet, loc.getZ());
        }
        fields[5].set(packet, 0);
        fields[6].set(packet, 0);
        fields[7].set(packet, 0);
        fields[8].set(packet, 0);
        fields[9].set(packet, 0);
        if (isPre14) fields[10].set(packet, type == EntityType.ARMOR_STAND ? 78 : 2);
        else fields[10].set(packet, entityType);
        fields[11].set(packet, 0);

        return packet;
    } catch (NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        plugin.getLogger().severe("Failed to create packet to spawn entity!");
        plugin.debug("Failed to create packet to spawn entity!");
        plugin.debug(e);
        return null;
    }
}
 
Example 8
Source File: ScrubEntityType.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Convert a string to a bukkit entity type.
 *
 * @param exprs The string to be converted.
 */
public static EntityType getType(String exprs) {
    switch (exprs.replace("\"", "").toLowerCase().replace("_", " ").replaceFirst("the ", "")) {
        case "player":
        case "the player":
            return EntityType.PLAYER;
        case "pig":
            return EntityType.PIG;
        case "blaze":
            return EntityType.BLAZE;
        case "bat":
            return EntityType.BAT;
        case "chicken":
            return EntityType.CHICKEN;
        case "creeper":
            return EntityType.CREEPER;
        case "cow":
            return EntityType.COW;
        case "enderman":
            return EntityType.ENDERMAN;
        case "ender dragon":
            return EntityType.ENDER_DRAGON;
        case "ghast":
            return EntityType.GHAST;
        case "giant":
            return EntityType.GIANT;
        case "iron golem":
            return EntityType.IRON_GOLEM;
        case "magma cube":
            return EntityType.MAGMA_CUBE;
        case "mushroom cow":
            return EntityType.MUSHROOM_COW;
        case "ocelot":
            return EntityType.OCELOT;
        case "pig zombie":
            return EntityType.PIG_ZOMBIE;
        case "sheep":
            return EntityType.SHEEP;
        case "silverfish":
            return EntityType.SILVERFISH;
        case "squid":
            return EntityType.SQUID;
        case "snowman":
            return EntityType.SNOWMAN;
        case "wolf":
            return EntityType.WOLF;
        case "skeleton":
            return EntityType.SKELETON;
        case "slime":
            return EntityType.SLIME;
        case "spider":
            return EntityType.SPIDER;
        case "witch":
            return EntityType.WITCH;
        case "wither":
            return EntityType.WITHER;
        case "villager":
            return EntityType.VILLAGER;
        case "zombie":
            return EntityType.ZOMBIE;
        case "armor stand":
            return EntityType.ARMOR_STAND;
        case "guardian":
            return EntityType.GUARDIAN;
        default:
            return EntityType.PLAYER;
    }
}