Java Code Examples for org.bukkit.entity.EntityType

The following examples show how to use org.bukkit.entity.EntityType. These examples are extracted from open source projects. 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 Project: helper   Author: lucko   File: CitizensNpcFactory.java    License: 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 #2
Source Project: ViaVersion   Author: ViaVersion   File: PlayerSneakListener.java    License: 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 #3
Source Project: CratesPlus   Author: ConnorLinfoot   File: CrateHandler.java    License: 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 #4
Source Project: HubBasics   Author: Fabricio20   File: Holograms.java    License: 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 #5
Source Project: QuickShop-Reremake   Author: Ghost-chu   File: RealDisplayItem.java    License: 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 #6
Source Project: Modern-LWC   Author: Tsuser1   File: LWC.java    License: 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 #7
Source Project: Sentinel   Author: mcmonkeyprojects   File: SentinelVersionCompat.java    License: 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 #8
Source Project: NBTEditor   Author: goncalomb   File: CustomFirework.java    License: 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 #9
Source Project: BedwarsRel   Author: BedwarsRel   File: EntityListener.java    License: 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 #10
Source Project: factions-top   Author: novucs   File: ChunkLoader.java    License: 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 #11
Source Project: AdditionsAPI   Author: chrismin13   File: CustomElytraPlayerToggleGlide.java    License: 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 #12
Source Project: UhcCore   Author: Mezy   File: DragonRushListener.java    License: 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 #13
Source Project: civcraft   Author: netizen539   File: ConfigTempleSacrifice.java    License: 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 #14
Source Project: factions-top   Author: novucs   File: FactionSpawnerModel.java    License: 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 #15
Source Project: RedProtect   Author: FabioZumbi12   File: KillCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    World world;
    EntityType entity = null;

    if (args.length == 0) {
        world = sender instanceof Player ? ((Player) sender).getWorld() : null;
    } else if (args.length == 1) {
        world = Bukkit.getWorld(args[0]);
    } else if (args.length == 2) {
        world = Bukkit.getWorld(args[0]);
        try {
            entity = EntityType.valueOf(args[1].toUpperCase());
        } catch (Exception ignored) {
            RedProtect.get().lang.sendCommandHelp(sender, "kill", true);
            return true;
        }
    } else {
        RedProtect.get().lang.sendCommandHelp(sender, "kill", true);
        return true;
    }

    if (world == null) {
        RedProtect.get().lang.sendMessage(sender, "cmdmanager.region.invalidworld");
        return true;
    }

    handleKillWorld(sender, world, entity);
    return true;
}
 
Example #16
Source Project: SonarPet   Author: TechzoneMC   File: NMSSpawnEggItemData.java    License: 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 #17
Source Project: Sentinel   Author: mcmonkeyprojects   File: SentinelVersionCompat.java    License: 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 #18
Source Project: Kettle   Author: KettleFoundation   File: CraftMetaSpawnEgg.java    License: 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 #19
Source Project: LanguageUtils   Author: MascusJeoraly   File: LanguageHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testGetEntityDisplayName() throws IOException {
    Entity entity1 = mock(Entity.class);

    when(entity1.getType()).thenReturn(EntityType.CREEPER);
    when(entity1.getCustomName()).thenReturn("Ssssssssss");
    assertEquals("Ssssssssss", LanguageHelper.getEntityDisplayName(entity1, "en_us"));

    Entity entity2 = mock(Entity.class);

    when(entity2.getType()).thenReturn(EntityType.BOAT);
    assertEquals("Boat", LanguageHelper.getEntityDisplayName(entity2, "en_us"));
}
 
Example #20
Source Project: QualityArmory   Author: ZombieStriker   File: Gunner.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Gunner createGunner(Location loc, final String gun) {
	final Gunner gunner = new Gunner();
	gunner.gunner = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "GunnerTest");
	gunner.gunner.spawn(loc);
	QAMain.gunners.add(gunner);
	SkinnableEntity se = ((SkinnableEntity)gunner.gunner.getEntity());
	se.setSkinName("army");
	// gunner.gunner.addTrait(GunnerTrait.class);
	// new BukkitRunnable() {
	// @Override
	// public void run() {
	Gun g = me.zombie_striker.qg.api.QualityArmory.getGunByName(gun);
	if (g == null) {
		Bukkit.broadcastMessage("gun is null");
	} else {
		((Player) gunner.gunner.getEntity()).setItemInHand(CustomItemManager.getItemType("gun").getItem(g.getItemData().getMat(),g.getItemData().getData(),g.getItemData().getVariant()));
	}
	gunner.gunner.getDefaultGoalController().addGoal(new Gunnergoal(gunner, g), 1);
	
	//LookClose lookclose = new LookClose();
	//lookclose.setRange(64);
	//lookclose.setRealisticLooking(true);
	//lookclose.linkToNPC(gunner.gunner);
	//gunner.gunner.addTrait(lookclose);

	// }
	// }.runTaskLater(Main.getInstance(), 1);

	return gunner;
}
 
Example #21
Source Project: factions-top   Author: novucs   File: ChunkLoader.java    License: MIT License 5 votes vote down vote up
public Map<ChunkPos, ChunkWorth> load() throws SQLException {
    Map<ChunkPos, ChunkWorth> target = new HashMap<>();
    Map<Integer, ChunkPos> chunks = loadChunk();
    Table<Integer, Material, Integer> globalMaterialCount = loadChunkMaterial();
    Table<Integer, EntityType, Integer> globalSpawnerCount = loadChunkSpawner();
    Table<Integer, WorthType, Double> globalWorth = loadChunkWorth();

    for (Map.Entry<Integer, ChunkPos> entry : chunks.entrySet()) {
        int chunkId = entry.getKey();

        Map<Material, Integer> chunkMaterialCount = new EnumMap<>(Material.class);
        chunkMaterialCount.putAll(globalMaterialCount.row(chunkId));

        Map<EntityType, Integer> chunkSpawnerCount = new EnumMap<>(EntityType.class);
        chunkSpawnerCount.putAll(globalSpawnerCount.row(chunkId));

        Map<WorthType, Double> chunkWorth = new EnumMap<>(WorthType.class);
        chunkWorth.putAll(globalWorth.row(chunkId));

        ChunkPos chunk = entry.getValue();
        ChunkWorth worth = new ChunkWorth(chunkWorth, chunkMaterialCount, chunkSpawnerCount);

        target.put(chunk, worth);
    }

    return target;
}
 
Example #22
Source Project: skRayFall   Author: eyesniper2   File: ArmorStandListener.java    License: 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 #23
Source Project: BedWars   Author: ScreamingSandals   File: WorldListener.java    License: 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 #24
Source Project: CardinalPGM   Author: twizmwazin   File: TntTracker.java    License: 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 #25
Source Project: Thermos   Author: CyberdyneCC   File: CraftCreatureSpawner.java    License: 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 #26
Source Project: SonarPet   Author: TechzoneMC   File: NMSSpawnEggItemData.java    License: 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 #27
Source Project: uSkyBlock   Author: rlf   File: LimitLogic.java    License: 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 #28
Source Project: PlotMe-Core   Author: WorldCretornica   File: SchematicUtil.java    License: 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 #29
Source Project: UhcCore   Author: Mezy   File: EntityDeathListener.java    License: 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 #30
Source Project: MineableSpawners   Author: dnyferguson   File: NMS_1_11_R1.java    License: 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);
}