org.bukkit.entity.EntityType Java Examples

The following examples show how to use org.bukkit.entity.EntityType. 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: CustomFirework.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
protected final Firework fire(Location location, IConsumableDetails details, Object userObject) {
	final Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
	FireworkMeta meta = firework.getFireworkMeta();
	final FireworkPlayerDetails fDetails = FireworkPlayerDetails.fromConsumableDetails(details, firework, userObject);
	if (!onFire(fDetails, meta)) {
		firework.remove();
		return null;
	}
	firework.setFireworkMeta(meta);

	final BukkitTask[] task = new BukkitTask[1];
	task[0] = Bukkit.getScheduler().runTaskTimer(getPlugin(), new Runnable() {
		@Override
		public void run() {
			if (firework.isDead()) {
				onExplode(fDetails);
				task[0].cancel();
			}
			firework.setTicksLived(Integer.MAX_VALUE);
		}
	}, 10 * (1 + meta.getPower()), 2);
	return firework;
}
 
Example #2
Source File: CitizensNpcFactory.java    From helper with MIT License 6 votes vote down vote up
private CitizensNpc spawnNpc(Location location, String nametag, Consumer<Npc> skin) {
    Objects.requireNonNull(this.npcRegistry, "npcRegistry");

    // create a new npc
    NPC npc = this.npcRegistry.createNPC(EntityType.PLAYER, nametag);

    // add the trait
    ClickableTrait trait = new ClickableTrait();
    npc.addTrait(trait);

    // create a new helperNpc instance
    CitizensNpc helperNpc = new NpcImpl(npc, trait, location.clone());
    trait.npc = helperNpc;

    // apply the skin and spawn it
    skin.accept(helperNpc);
    npc.spawn(location);

    return helperNpc;
}
 
Example #3
Source File: PlayerSneakListener.java    From ViaVersion with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void playerDamage(EntityDamageEvent event) {
    if (!is1_14Fix) return;
    if (event.getCause() != EntityDamageEvent.DamageCause.SUFFOCATION) return;
    if (event.getEntityType() != EntityType.PLAYER) return;

    Player player = (Player) event.getEntity();
    if (!sneakingUuids.contains(player.getUniqueId())) return;

    // Don't cancel when they should actually be suffocating; Essentially cancel when the head is in the top block only ever so slightly
    // ~0.041 should suffice, but gotta stay be safe
    double y = player.getEyeLocation().getY() + 0.045;
    y -= (int) y;
    if (y < 0.09) {
        event.setCancelled(true);
    }
}
 
Example #4
Source File: CustomElytraPlayerToggleGlide.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onCustomElytraPlayerGlideLowest(CustomElytraPlayerToggleGlideEvent customEvent) {
	if (customEvent.isCancelled())
		return;

	CustomItem cItem = customEvent.getCustomItem();

	if (!(cItem.getPermissions() instanceof ElytraPermissions))
		return;
	ElytraPermissions perm = (ElytraPermissions) cItem.getPermissions();

	EntityToggleGlideEvent event = customEvent.getEntityToggleGlideEvent();

	if (event.getEntity().getType().equals(EntityType.PLAYER)
			&& !PermissionUtils.allowedAction((Player) event.getEntity(), perm.getType(), perm.getFlight()))
		event.setCancelled(true);
}
 
Example #5
Source File: CrateHandler.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
public void spawnFirework(Location location) {
    Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
    FireworkMeta fwm = fw.getFireworkMeta();
    Random r = new Random();
    int rt = r.nextInt(4) + 1;
    FireworkEffect.Type type = FireworkEffect.Type.BALL;
    if (rt == 1) type = FireworkEffect.Type.BALL;
    if (rt == 2) type = FireworkEffect.Type.BALL_LARGE;
    if (rt == 3) type = FireworkEffect.Type.BURST;
    if (rt == 4) type = FireworkEffect.Type.CREEPER;
    if (rt == 5) type = FireworkEffect.Type.STAR;
    int r1i = r.nextInt(17) + 1;
    int r2i = r.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);
    FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
    fwm.addEffect(effect);
    int rp = r.nextInt(2) + 1;
    fwm.setPower(rp);
    fw.setFireworkMeta(fwm);
}
 
Example #6
Source File: ChunkLoader.java    From factions-top with MIT License 6 votes vote down vote up
private Table<Integer, EntityType, Integer> loadChunkSpawner() throws SQLException {
    Table<Integer, EntityType, Integer> target = HashBasedTable.create();
    ResultSet resultSet = selectChunkSpawner.executeQuery();

    while (resultSet.next()) {
        int id = resultSet.getInt("id");
        int chunkId = resultSet.getInt("chunk_id");
        int spawnerId = resultSet.getInt("spawner_id");
        int count = resultSet.getInt("count");

        identityCache.setChunkSpawnerId(chunkId, spawnerId, id);
        identityCache.getSpawner(spawnerId).ifPresent(spawner ->
                target.put(chunkId, spawner, count));
    }

    resultSet.close();
    return target;
}
 
Example #7
Source File: Holograms.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
private JSONArray spawnLines(Location loc, String[] lines) {
    int lineIndex = 0;
    JSONArray array = new JSONArray();

    for (String str : lines) {
        ArmorStand armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
        armorStand.setGravity(false);
        armorStand.setVisible(false);
        armorStand.setCustomName(ChatColor.translateAlternateColorCodes('&', str));
        armorStand.setCustomNameVisible(true);
        armorStand.setRemoveWhenFarAway(false);
        loc.setY(loc.getY() - 0.25);

        JSONObject object = new JSONObject();
        object.put(ARMORSTAND_LINE, lineIndex);
        object.put(ARMORSTAND_TEXT, str);
        object.put(ARMORSTAND_UUID, armorStand.getUniqueId().toString());
        array.put(lineIndex, object);
        lineIndex++;
    }

    return array;
}
 
Example #8
Source File: SentinelVersionCompat.java    From Sentinel with MIT License 6 votes vote down vote up
static EntityType[] v1_16_monsters() {
    return new EntityType[]{
            // 1.8 minus PigZombie
            EntityType.GUARDIAN, EntityType.CREEPER, EntityType.SKELETON, EntityType.ZOMBIE,
            EntityType.MAGMA_CUBE, EntityType.SILVERFISH, EntityType.BAT, EntityType.BLAZE,
            EntityType.GHAST, EntityType.GIANT, EntityType.SLIME, EntityType.SPIDER, EntityType.CAVE_SPIDER, EntityType.ENDERMAN,
            EntityType.ENDERMITE, EntityType.WITHER, EntityType.ENDER_DRAGON, EntityType.WITCH,
            // 1.9
            EntityType.SHULKER,
            // 1.11
            EntityType.VEX, EntityType.HUSK, EntityType.ELDER_GUARDIAN,
            EntityType.EVOKER, EntityType.STRAY, EntityType.ZOMBIE_VILLAGER,
            EntityType.WITHER_SKELETON, EntityType.VINDICATOR,
            // 1.12
            EntityType.ILLUSIONER,
            // 1.13
            EntityType.DROWNED, EntityType.PHANTOM,
            // 1.14
            EntityType.RAVAGER, EntityType.PILLAGER,
            // 1.15
            EntityType.BEE,
            // 1.16
            EntityType.HOGLIN, EntityType.PIGLIN, EntityType.ZOGLIN, EntityType.ZOMBIFIED_PIGLIN
    };
}
 
Example #9
Source File: RealDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeDupe() {
    if (this.item == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }

    boolean removed = false;
    // Chunk chunk = shop.getLocation().getChunk();
    for (Entity entity : item.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.DROPPED_ITEM) {
            continue;
        }
        Item eItem = (Item) entity;
        UUID displayUUID = this.item.getUniqueId();
        if (!eItem.getUniqueId().equals(displayUUID)) {
            if (DisplayItem.checkIsTargetShopDisplay(eItem.getItemStack(), this.shop)) {
                Util.debugLog(
                        "Removing a duped ItemEntity " + eItem.getUniqueId() + " at " + eItem.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
Example #10
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent ede) {
  List<EntityType> canDamageTypes = new ArrayList<EntityType>();
  canDamageTypes.add(EntityType.PLAYER);

  if (BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AntiAura")
      || BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AAC")) {
    canDamageTypes.add(EntityType.SQUID);
  }

  if (canDamageTypes.contains(ede.getEntityType())) {
    return;
  }

  Game game =
      BedwarsRel.getInstance().getGameManager().getGameByLocation(ede.getEntity().getLocation());
  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  ede.setCancelled(true);
}
 
Example #11
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
public String resolveProtectionConfiguration(EntityType state, String node) {
    String cacheKey = state + "-" + state + "-" + node;
    if (protectionConfigurationCache.containsKey(cacheKey)) {
        return protectionConfigurationCache.get(cacheKey);
    }

    String value = configuration.getString("protections." + node);

    String temp = configuration.getString("protections.blocks." + state.name().toUpperCase() + "." + node);

    if (temp != null && !temp.isEmpty()) {
        value = temp;
    }

    protectionConfigurationCache.put(cacheKey, value);
    return value;
}
 
Example #12
Source File: SentinelVersionCompat.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Combines two arrays of EntityType values.
 */
public static EntityType[] combine(EntityType[] a, EntityType... b) {
    EntityType[] types = new EntityType[a.length + b.length];
    for (int i = 0; i < a.length; i++) {
        types[i] = a[i];
    }
    for (int i = 0; i < b.length; i++) {
        types[i + a.length] = b[i];
    }
    return types;
}
 
Example #13
Source File: CraftMetaSpawnEgg.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
void deserializeInternal(NBTTagCompound tag) {
    super.deserializeInternal(tag);

    if (tag.hasKey(ENTITY_TAG.NBT)) {
        entityTag = tag.getCompoundTag(ENTITY_TAG.NBT);
        MinecraftServer.getServerCB().getDataFixer().process(FixTypes.ENTITY, entityTag); // PAIL: convert TODO: identify DataConverterTypes after implementation

        if (entityTag.hasKey(ENTITY_ID.NBT)) {
            this.spawnedType = EntityType.fromName(new ResourceLocation(entityTag.getString(ENTITY_ID.NBT)).getResourcePath());
        }
    }
}
 
Example #14
Source File: WrappedEntityType.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public EntityType get() {
    try {
        return EntityType.valueOf(this.entityTypeName);
    } catch (Exception exception) {
        return null;
    }
}
 
Example #15
Source File: NMSSpawnEggItemData.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static ItemMeta createMetaWithEntityType(ItemMeta meta, EntityType entityType) {
    NBTTagCompound entityTag = new NBTTagCompound();
    String internalName = EntityTypes.getName(EntityTypes.a(entityType.getTypeId()));
    if (internalName == null) throw new AssertionError("Couldn't find internal name for type: " + entityType);
    entityTag.setString("id", internalName);
    NBTTagCompound tag = getTagFromMeta(Material.MONSTER_EGG, Preconditions.checkNotNull(meta, "Null meta"));
    if (tag == null) tag = new NBTTagCompound();
    tag.set("EntityTag", entityTag);
    return createMetaFromTag(Material.MONSTER_EGG, tag);
}
 
Example #16
Source File: EffCreateCitizen.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    EntityType citizenType = ScrubEntityType.getType(type.toString());
    NPC npc = registry.createNPC(citizenType, name.getSingle(evt).toString().replace("\"", ""));
    Location spawnto = location.getSingle(evt);
    npc.spawn(spawnto);
    ExprLastCitizen.lastNPC = npc;

}
 
Example #17
Source File: FactionSpawnerModel.java    From factions-top with MIT License 5 votes vote down vote up
public void addBatch(String factionId, Map<EntityType, Integer> spawners) throws SQLException {
    // Persist all spawner counters for this specific faction worth.
    for (Map.Entry<EntityType, Integer> entry : spawners.entrySet()) {
        EntityType spawner = entry.getKey();
        int count = entry.getValue();
        int spawnerId = identityCache.getSpawnerId(spawner.name());
        addBatch(factionId, spawnerId, count);
    }
}
 
Example #18
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 #19
Source File: ConfigTempleSacrifice.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isValidEntity(EntityType entityType) {
	if (validEntities.contains(entityType.toString())) {
		return true;
	}
	
	return false;
}
 
Example #20
Source File: LimitLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public boolean canSpawn(EntityType entityType, us.talabrek.ultimateskyblock.api.IslandInfo islandInfo) {
    Map<CreatureType, Integer> creatureCount = getCreatureCount(islandInfo);
    CreatureType creatureType = getCreatureType(entityType);
    int max = getMax(islandInfo, creatureType);
    if (creatureCount.containsKey(creatureType) && creatureCount.get(creatureType) >= max) {
        return false;
    }
    return true;
}
 
Example #21
Source File: ArmorStandListener.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Listener used to generate the ArmorStandDamageEvent.
 *
 * @param evt The initial EntityDamageByEntityEvent event
 *            used to generate the ArmorStandDamageEvent
 */
@EventHandler
public void onArmorStandDamage(EntityDamageByEntityEvent evt) {
    if (evt.getEntity().getType().equals(EntityType.ARMOR_STAND)
            && evt.getDamager().getType().equals(EntityType.PLAYER)) {
        ArmorStandDamageEvent event =
                new ArmorStandDamageEvent((Player) evt.getDamager(), evt.getEntity());
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            evt.setCancelled(true);
            return;
        }
    }
}
 
Example #22
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                if (event.getEntityType() == EntityType.FALLING_BLOCK
                        && game.getOriginalOrInheritedAllowBlockFalling()) {
                    if (event.getBlock().getType() != event.getTo()) {
                        if (!game.getRegion().isBlockAddedDuringGame(event.getBlock().getLocation())) {
                            if (event.getBlock().getType() != Material.AIR) {
                                game.getRegion().putOriginalBlock(event.getBlock().getLocation(),
                                        event.getBlock().getState());
                            }
                            game.getRegion().addBuiltDuringGame(event.getBlock().getLocation());
                        }
                    }
                    return; // allow block fall
                }
            }

            if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example #23
Source File: TntTracker.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static UUID getWhoPlaced(Entity tnt) {
    if (tnt.getType().equals(EntityType.PRIMED_TNT)) {
        if (tnt.hasMetadata("source")) {
            return (UUID) tnt.getMetadata("source").get(0).value();
        }
    }
    return null;
}
 
Example #24
Source File: DragonRushListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent e){
    if (e.getEntityType() != EntityType.ENDER_DRAGON){
        return;
    }

    if (e.getEntity().getKiller() == null) {
        return;
    }

    Player killer = e.getEntity().getKiller();
    UhcPlayer uhcKiller = getPlayersManager().getUhcPlayer(killer);

    List<UhcPlayer> spectators = new ArrayList<>();

    for (UhcPlayer playingPlayer : getPlayersManager().getAllPlayingPlayers()){

        if (!playingPlayer.isInTeamWith(uhcKiller)){
            spectators.add(playingPlayer);
        }
    }

    for (UhcPlayer spectator : spectators){
        spectator.setState(PlayerState.DEAD);

        try {
            Player all = spectator.getPlayer();
            all.setGameMode(GameMode.SPECTATOR);
            all.teleport(killer);
        }catch (UhcPlayerNotOnlineException exeption){
            // Nothing
        }
    }

    getPlayersManager().checkIfRemainingPlayers();
}
 
Example #25
Source File: NMS_1_11_R1.java    From MineableSpawners with MIT License 5 votes vote down vote up
@Override
public ItemStack setType(ItemStack itemStack, EntityType type) {
    net.minecraft.server.v1_11_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound nmsItemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound();
    if (nmsItemCompound == null) {
        return null;
    }
    nmsItemCompound.set("ms_mob", new NBTTagString(type.name()));
    nmsItem.setTag(nmsItemCompound);

    return CraftItemStack.asBukkitCopy(nmsItem);
}
 
Example #26
Source File: CraftCreatureSpawner.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setCreatureTypeByName(String creatureType) {
    // Verify input
    EntityType type = EntityType.fromName(creatureType);
    if (type == null) {
        return;
    }
    setSpawnedType(type);
}
 
Example #27
Source File: EntityDeathListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void handleMobLoot(EntityDeathEvent event){
	EntityType entity = event.getEntityType();
	if(mobLoots.containsKey(entity)){
		MobLootConfiguration lootConfig = mobLoots.get(entity);
		event.getDrops().clear();
		event.getDrops().add(lootConfig.getLoot().clone());
		event.setDroppedExp(lootConfig.getAddXp());
		UhcItems.spawnExtraXp(event.getEntity().getLocation(),lootConfig.getAddXp());
	}
}
 
Example #28
Source File: NMSSpawnEggItemData.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static EntityType getSpawnEggEntityType(ItemMeta meta) {
    Preconditions.checkNotNull(meta, "Null meta");
    NBTTagCompound tag = getTagFromMeta(Material.MONSTER_EGG, meta);
    Preconditions.checkState(tag != null, "No nbt tag");
    Preconditions.checkState(tag.hasKeyOfType("EntityTag", 10), "No entity tag");
    NBTTagCompound entityTag = tag.getCompound("EntityTag");
    Preconditions.checkState(entityTag.hasKeyOfType("id", 8), "No internal name");
    String internalName = entityTag.getString("id");
    int id = EntityTypes.a(internalName);
    EntityType type = EntityType.fromId(id);
    if (type == null)
        throw new IllegalStateException("No entity found with internal name " + internalName + " and id " + id);
    return type;
}
 
Example #29
Source File: SchematicUtil.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
private org.bukkit.entity.Entity getLeash(IWorld world1, Leash leash, com.worldcretornica.plotme_core.api.Vector loc, int originX, int originY,
        int originZ) {
    org.bukkit.entity.Entity ent = null;
    World world = ((BukkitWorld) world1).getWorld();

    int x = leash.getX() - originX;
    int y = leash.getY() - originY;
    int z = leash.getZ() - originZ;

    org.bukkit.Location etloc = new org.bukkit.Location(world, x + loc.getBlockX(), y + loc.getBlockY(), z + loc.getBlockZ());

    Block block = world.getBlockAt(etloc);

    if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
        etloc.setX(Math.floor(etloc.getX()));
        etloc.setY(Math.floor(etloc.getY()));
        etloc.setZ(Math.floor(etloc.getZ()));

        ent = world.spawnEntity(etloc, EntityType.LEASH_HITCH);

        List<org.bukkit.entity.Entity> nearbyentities = ent.getNearbyEntities(1, 1, 1);

        for (org.bukkit.entity.Entity nearby : nearbyentities) {
            if (nearby instanceof LeashHitch) {
                if (nearby.getLocation().distance(ent.getLocation()) == 0) {
                    ent.remove();
                    return nearby;
                }
            }
        }
    }

    return ent;
}
 
Example #30
Source File: HorsesModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler
public void on(EntityMountEvent event) {
    if (isEnabled() || event.getEntityType() != EntityType.PLAYER) return;

    if (event.getMount().getType() == EntityType.HORSE) {
        event.setCancelled(true);
        event.getEntity().sendMessage(messages.getRaw("disabled message"));
    }
}