Java Code Examples for org.bukkit.entity.EntityType

The following are top voted examples for showing how to use org.bukkit.entity.EntityType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: UHC   File: JoinQuitHandlers.java   Source Code and License 7 votes vote down vote up
@EventHandler
public void leave(final PlayerQuitEvent event) {
    if(GameState.current() != GameState.LOBBY && event.getPlayer().getGameMode() != GameMode.SPECTATOR){
        event.setQuitMessage(colour("&6" + event.getPlayer().getName() + " has quit! " +
                "They have " + UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds() + "s to reconnect."));

        bukkitRunnable(() -> disqualified(event.getPlayer().getUniqueId(), event.getPlayer().getName(),
                event.getPlayer().getLocation(), event.getPlayer().getInventory())).runTaskLater(UHC.getInstance(),
                TimeUnit.MILLISECONDS.convert(UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds(), TimeUnit.SECONDS));

        //Zombie Spawning
        Zombie zombie = (Zombie) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.ZOMBIE);
        zombie.setCustomName(event.getPlayer().getName());
        zombie.setCustomNameVisible(true);
        //TODO Make no AI and invulnerable cough cough Proxi cough cough
        deadRepresentatives.put(event.getPlayer().getUniqueId(), zombie);
    }
}
 
Example 2
Project: Chambers   File: VillagerManager.java   Source Code and License 6 votes vote down vote up
/**
 * Spawns a Villager of the given VillagerType at the provided Location
 * 
 * @param type - the Type of the Villager you wish to Spawn
 * @param location - the Location at which you want the Villager to be
 * @return Villager - the Villager that you had set at the provided Location if you wish to use it
 */
public Villager spawnVillager(VillagerType type, Location location) {
	if (!location.getChunk().isLoaded()) {
		location.getChunk().load();
	}
	Villager villager = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
	villager.setAdult();
	villager.setAgeLock(true);
	villager.setProfession(Profession.FARMER);
	villager.setRemoveWhenFarAway(false);
	villager.setCustomName(type.getColor() + type.getName());
	villager.setCustomNameVisible(true);
	villager.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, -6, true), true);
	villager.teleport(location, TeleportCause.PLUGIN);
	villager.setHealth(20.0D);
	return villager;
}
 
Example 3
Project: bskyblock   File: IslandGuard1_8.java   Source Code and License 6 votes vote down vote up
/**
 * Handle interaction with armor stands V1.8
 * Note - some armor stand protection is done in IslandGuard.java, e.g. against projectiles.
 *
 * @param e
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + e.getEventName());
    }
    if (!Util.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ARMOR_STAND)) {
        if (actionAllowed(e.getPlayer(), e.getRightClicked().getLocation(), SettingsFlag.ARMOR_STAND)) {
            return;
        }
        e.setCancelled(true);
        Util.sendMessage(e.getPlayer(), plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
    }
}
 
Example 4
Project: PA   File: AntiGravity.java   Source Code and License 6 votes vote down vote up
@Override
public void play(PAUser u) {
    if (isInCooldown(u, getName())) return;

    final ArmorStand as = (ArmorStand) spawnEntity(u.getLoc(), EntityType.ARMOR_STAND);
    as.setGravity(false);
    as.setSmall(true);
    as.setVisible(false);
    as.setHelmet(new ItemStack(Material.SEA_LANTERN));
    as.setPassenger(u.getPlayer());

    as.teleport(as.getLocation().add(0, 5, 0));

    bt = plugin.getServer().getScheduler().runTaskTimer(plugin, ()-> {
        as.teleport(as.getLocation().add(0, 0.2, 0));

        if (count <= 0) {
            remove(u, as);
            bt.cancel();
            return;
        }
        count--;
    }, 0, 20);
}
 
Example 5
Project: AsgardAscension   File: ChallengeListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onMobDeath(EntityDeathEvent event) {
	if(event.getEntity() instanceof Entity){
		Entity e = (Entity) event.getEntity();
		if(e.hasMetadata("challenge")){
			event.getDrops().clear();
			String[] meta = e.getMetadata("challenge").get(0).asString().split(", ");
			final String player = meta[1];
			plugin.getChallenges().addKill(Bukkit.getPlayer(player));
			Bukkit.getPlayer(player).setLevel(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)));
			if(e.getType().equals(EntityType.MAGMA_CUBE) || e.getType().equals(EntityType.SLIME)) {
				e.remove();
			}
			if(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)) == 0){
				plugin.getChallenges().finishChallenge(Bukkit.getPlayer(player), false);
			}
		}
	}
}
 
Example 6
Project: bskyblock   File: Schematic.java   Source Code and License 6 votes vote down vote up
/**
 * Spawns a random companion for the player with a random name at the location given
 * @param player
 * @param location
 */
protected void spawnCompanion(Player player, Location location) {
    // Older versions of the server require custom names to only apply to Living Entities
    //Bukkit.getLogger().info("DEBUG: spawning compantion at " + location);
    if (!islandCompanion.isEmpty() && location != null) {
        Random rand = new Random();
        int randomNum = rand.nextInt(islandCompanion.size());
        EntityType type = islandCompanion.get(randomNum);
        if (type != null) {
            LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type);
            if (!companionNames.isEmpty()) {
                randomNum = rand.nextInt(companionNames.size());
                String name = companionNames.get(randomNum).replace("[player]", player.getName());
                //plugin.getLogger().info("DEBUG: name is " + name);
                companion.setCustomName(name);
                companion.setCustomNameVisible(true);
            }
        }
    }
}
 
Example 7
Project: SurvivalAPI   File: ThreeArrowModule.java   Source Code and License 6 votes vote down vote up
/**
 * Launch 2 more arrows when one is launched
 *
 * @param event Event
 */
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event)
{
    if (event.getEntity().getType() != EntityType.ARROW || !(event.getEntity().getShooter() instanceof Player) || event.getEntity().hasMetadata("TAM"))
        return;

    final Vector velocity = event.getEntity().getVelocity();

    for(int i = 0; i < 2; i++)
    {
        this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () ->
        {
            EntityArrow entityArrow = new EntityArrow(((CraftWorld)event.getEntity().getWorld()).getHandle(), ((CraftLivingEntity)event.getEntity().getShooter()).getHandle(), 1F);
            entityArrow.shoot(((CraftLivingEntity)event.getEntity().getShooter()).getHandle().pitch, ((CraftLivingEntity)event.getEntity().getShooter()).getHandle().yaw, 0.0F, 3.0F, 1.0F);
            entityArrow.getBukkitEntity().setMetadata("TAM", new FixedMetadataValue(this.plugin, true));
            entityArrow.getBukkitEntity().setVelocity(velocity);
            ((CraftWorld)event.getEntity().getWorld()).getHandle().addEntity(entityArrow);
        }, 5L * (i + 1));
    }
}
 
Example 8
Project: Locked   File: MerchantListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    try {
        int balance = ScrapsUtil.getScraps(player);
        if (entity.getType().equals(EntityType.VILLAGER)) {
            event.setCancelled(true);
            String npc = entity.getName();
            if (MerchantManager.getAllNPCs().contains(npc)) {
                ItemStack selling = MerchantManager.getItem(npc);
                int price = MerchantManager.getPrice(npc);
                if (balance >= price) {
                    player.getInventory().addItem(selling);
                    player.sendMessage(MerchantManager.getSuccessMessage(npc));
                    ScrapsUtil.removeScraps(player, price);
                } else {
                    player.sendMessage(MerchantManager.getDenialMessage(npc));
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 9
Project: Sunscreen   File: PluginSettings.java   Source Code and License 6 votes vote down vote up
/**
 * Load the plugin's settings.
 *
 * @author HomieDion
 * @since 1.1.0
 */
public void load() {
	// Variables
	final Sunscreen plugin = Sunscreen.getInstance();
	final CustomConfig config = new CustomConfig("config.yml", plugin);
	final Logger log = plugin.getLogger();

	// Add the disabled worlds
	for (final String world : config.getStringList("disabled_worlds")) {
		worlds.add(world);
		log.info(String.format("%s will not use this plugin.", world));
	}

	// Loop all entities
	for (final EntityType type : EntityType.values()) {
		// Loop all values of the list
		for (final String line : config.getStringList("mobs")) {
			// If the names match
			if (type.name().equalsIgnoreCase(line)) {
				mobs.add(type);
				log.info(String.format("%s will not burn in the sun.", type.name()));
				break;
			}
		}
	}
}
 
Example 10
Project: Hub   File: PaintballDisplayer.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onProjectileHit(ProjectileHitEvent event)
{
    if (event.getEntity().getType() != EntityType.SNOWBALL || !event.getEntity().hasMetadata("paintball-ball") || !event.getEntity().getMetadata("paintball-ball").get(0).asString().equals(this.uuid.toString()))
        return;

    for (Block block : getNearbyBlocks(event.getEntity().getLocation(), 2))
    {
        if (block.getType() == Material.AIR || block.getType() == Material.SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
            continue;

        if (this.isBlockGloballyUsed(block.getLocation()))
            continue;

        SimpleBlock simpleBlock = new SimpleBlock(Material.STAINED_CLAY, DyeColor.values()[new Random().nextInt(DyeColor.values().length)].getWoolData());
        this.addBlockToUse(block.getLocation(), simpleBlock);

        block.setType(simpleBlock.getType());
        block.setData(simpleBlock.getData());
    }

    event.getEntity().remove();
}
 
Example 11
Project: EchoPet   File: SpawnUtil.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
// This is kind of a dumb way to do this.. But I'm too lazy to fix my reflection
public org.bukkit.inventory.ItemStack getSpawnEgg(org.bukkit.inventory.ItemStack i, String entityTag){
	EntityType type = null;
	try{
		type = EntityType.valueOf(entityTag.toUpperCase());
	}catch(Exception ex){
		switch (entityTag){
			case "mooshroom":
				type = EntityType.MUSHROOM_COW;
				break;
			case "zombie_pigman":
				type = EntityType.PIG_ZOMBIE;
				break;
			default:
				type = EntityType.BAT;
				System.out.println("Bad tag: " + entityTag);
				break;
		}
	}
	return new ItemStack(i.getType(), i.getAmount(), type.getTypeId());
}
 
Example 12
Project: EscapeLag   File: AntiLongStringCrash.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void ClickCheckItem(InventoryClickEvent evt){
    if(ConfigPatch.AntiLongStringCrashenable == true){
        if(evt.getWhoClicked().getType() != EntityType.PLAYER){
            return;
        }
        Player player = (Player) evt.getWhoClicked();
        ItemStack item = evt.getCursor();
        if(item != null){
            if(item.hasItemMeta() && item.getItemMeta().getDisplayName() != null){
                if(item.getItemMeta().getDisplayName().length() >= 127){
                    evt.setCancelled(true);
                    evt.setCurrentItem(null);
                    AzureAPI.log(player, ConfigPatch.AntiLongStringCrashWarnMessage);
                }
            }
        }
    }
}
 
Example 13
Project: RPGInventory   File: LocationUtils.java   Source Code and License 5 votes vote down vote up
public static List<Player> getNearbyPlayers(Location location, double distance) {
    List<Player> nearbyPlayers = new ArrayList<>();
    for (LivingEntity entity : location.getWorld().getLivingEntities()) {
        if (entity.getType() == EntityType.PLAYER && entity.getLocation().distance(location) <= distance) {
            nearbyPlayers.add((Player) entity);
        }
    }

    return nearbyPlayers;
}
 
Example 14
Project: ProjectAres   File: RocketUtils.java   Source Code and License 5 votes vote down vote up
public static Firework getRandomFirework(Location loc) {
    FireworkMeta fireworkMeta = (FireworkMeta) (new ItemStack(Material.FIREWORK)).getItemMeta();
    Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);

    fireworkMeta.setPower(GizmoConfig.FIREWORK_POWER);
    fireworkMeta.addEffect(FireworkEffect.builder()
            .with(RocketUtils.randomFireworkType())
            .withColor(RocketUtils.randomColor())
            .trail(GizmoConfig.FIREWORK_TRAIL)
            .build());

    firework.setFireworkMeta(fireworkMeta);
    return firework;
}
 
Example 15
Project: PA   File: KillAllCMD.java   Source Code and License 5 votes vote down vote up
private List<Entity> worldEntities(World w, EntityType entityType) {
    List<Entity> entities = new ArrayList<>();

    w.getEntities().forEach(e -> {
        if (e.getType() == entityType) {
            entities.add(e);
        }
    });
    return entities;
}
 
Example 16
Project: SuperiorCraft   File: DamageIndicator.java   Source Code and License 5 votes vote down vote up
@EventHandler
   public void onEntityDamageEvent(EntityDamageEvent e) {
	if (!(e.getEntity() instanceof ArmorStand) && e.getEntityType() != EntityType.ARMOR_STAND && e.getEntityType() != EntityType.DROPPED_ITEM) {
		Hologram h = new Hologram(ChatColor.RED + "-" + Double.toString(e.getDamage()) + " \u2764", e.getEntity().getLocation());
		h.getHologram().addScoreboardTag("dindicator");
		h.setKillTimer(2);
	}
	if (e.getEntity() instanceof Player) {
		Player player = (Player) e.getEntity();
		player.sendMessage(ChatColor.GRAY + "[DamageIndicator] " + e.getCause().name() + " did " + new DecimalFormat("#0.0").format(((double) Math.round(e.getDamage())) / 2) + ChatColor.RED + " \u2764");
	}
}
 
Example 17
Project: mczone   File: GeneralEvents.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onDestroyByEntity(HangingBreakByEntityEvent event) {
	if ((event.getRemover() instanceof Player)) {
		if (event.getEntity().getType() == EntityType.ITEM_FRAME) {
			event.setCancelled(true);
		}
	}
}
 
Example 18
Project: Mega-Walls   File: CreatureSpawnListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent e)
{
    if (e.getEntityType() != EntityType.PLAYER && e.getEntityType() != EntityType.WITHER)
    {
        if (MWAPI.getConfig().stopEntitySpawn())
        {
            e.setCancelled(true);
        }
    }
}
 
Example 19
Project: mczone   File: PetColorCmd.java   Source Code and License 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String[] args) {    	
   	if (args.length < 2) {
   		Chat.player(sender, "&2[Pets] &cUsage: /pet color [pet name] [color]");
   		return true;
   	}

   	Player p = (Player) sender;
   	String username = p.getName();
   	for (PetInstance pet : PetInstance.getList()) {
   		if (pet.getName().equalsIgnoreCase(args[0])) {
    		if (pet.getOwner().equalsIgnoreCase(username)) {
    			if (pet.getType() != EntityType.SHEEP) {
    				Chat.player(p, "&2[Pets] &cYou can only change the color of sheep.");
    				return true;
    			}
    			String[] nameArray = Arrays.copyOfRange(args, 1, args.length);
    			String c = Joiner.on("_").join(nameArray);
    			DyeColor color = null;
    			try {
    				color = DyeColor.valueOf(c.toUpperCase());
    			}
    			catch (IllegalArgumentException e) {
    				Chat.player(p, "&2[Pets] &cUnknown color: " + c + "!");
    				Chat.player(p, "&cColors: &7&o" + Joiner.on(", ").join(DyeColor.values()).toLowerCase().replace("_", " "));
    				return true;
    			}
    			
    			Chat.player(p, "&2[Pets] &aYou have changed the color of &e" + pet.getName() + "&a to " + c.replace("_", " "));
    			pet.setColor(color);
    			return true;
    		}
   		}
   	}
   	
   	Chat.player(p, "&2[Pets] &cYou do not own a pet by the name of &e" + args[0] + "\n      &7&oBuy customized pets at www.mczone.co/shop");
       return true;
}
 
Example 20
Project: SurvivalAPI   File: MobOresModule.java   Source Code and License 5 votes vote down vote up
/**
 * When a player breaks ore, spawn mob
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true)
public void onEntityDeath(BlockBreakEvent event)
{
    EntityType type;

    switch (event.getBlock().getType())
    {
        case COAL_ORE:
            type = EntityType.ZOMBIE;
            break;

        case IRON_ORE:
            type = EntityType.SKELETON;
            break;

        case GOLD_ORE:
            type = EntityType.SPIDER;
            break;

        case DIAMOND_ORE:
            type = EntityType.WITCH;
            break;

        default:
            type = null;
            break;
    }

    Entity entity;

    if (type != null && random.nextDouble() < (double) this.moduleConfiguration.get("chance"))
    {
        entity = event.getBlock().getWorld().spawnEntity(event.getBlock().getLocation(), type);

        if (type == EntityType.SKELETON)
            ((Skeleton) entity).getEquipment().clear(); //Remove skeleton bow
    }
}
 
Example 21
Project: SuperiorCraft   File: CustomTexturedBlock.java   Source Code and License 5 votes vote down vote up
@Override
public boolean placeBlock(ArmorStand e, Player p) {
	getTexture().placeBlock(e.getLocation().add(0, 0.125, -0.375));
	e.getLocation().getBlock().setType(getMaterial());
	if (getMaterial().equals(Material.MOB_SPAWNER)) {
		CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
		cs.setSpawnedType(EntityType.DROPPED_ITEM);
		cs.update();
	}
	setLe(e);
	return true;
}
 
Example 22
Project: DungeonGen   File: EntitySpawnTask.java   Source Code and License 5 votes vote down vote up
/**Constructor, passes arguments to super class and loads special values from config.
 * @param parent	The Room this Task belongs to
 * @param conf		Given config file of this room has entries on tasks.
 * @param taskNr	Task number is needed to load keys correctly.
 */
public EntitySpawnTask(Room parent, FileConfiguration conf, int taskNr) {
	super(parent, conf, taskNr);
	this.type = TaskType.ENTITYSPAWN;
	
	// loading values for this Task type:
	String path = "tasks.task" + this.taskNr + ".";
	grp = new EntityGroup();
	grp.type = EntityType.valueOf(conf.getString( path + "entityType"));
	grp.count = 				  conf.getInt(    path + "count");
	//TODO: maxCount noch einbauen -> bei jedem Spawning z�hlen, bei Tod runterz�hlen
	grp.maxCount =				  conf.getInt(    path + "maxCount");
	grp.isTarget = 				  conf.getBoolean(path + "isTarget");
}
 
Example 23
Project: bskyblock   File: IslandGuard1_8.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void ArmorStandDestroy(EntityDamageByEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + "IslandGuard New " + e.getEventName());
    }
    if (!(e.getEntity() instanceof LivingEntity)) {
        return;
    }
    if (!Util.inWorld(e.getEntity())) {
        return;
    }
    final LivingEntity livingEntity = (LivingEntity) e.getEntity();
    if (!livingEntity.getType().equals(EntityType.ARMOR_STAND)) {
        return;
    }
    if (e.getDamager() instanceof Player) {
        Player p = (Player) e.getDamager();
        if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check if on island
        if (plugin.getIslands().playerIsOnIsland(p)) {
            return;
        }
        // Check island
        Island island = plugin.getIslands().getIslandAt(e.getEntity().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null && island.getFlag(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        Util.sendMessage(p, plugin.getLocale(p.getUniqueId()).get("island.protected"));
        e.setCancelled(true);
    }
}
 
Example 24
Project: PA   File: KillAllCMD.java   Source Code and License 5 votes vote down vote up
private List<Entity> worldClassEntities(World w, EntityType entityType) {
    List<Entity> entities = new ArrayList<>();

    w.getEntitiesByClass(entityType.getEntityClass()).forEach(e -> {
        if (e.getType() == entityType) {
            entities.add(e);
        }
    });
    return entities;
}
 
Example 25
Project: mczone   File: GeneralEvents.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onEntityInteractEntity(PlayerInteractEntityEvent event) {
	if (event.getRightClicked().getType() == EntityType.ITEM_FRAME) {
		event.setCancelled(true);
		ItemFrame frame = (ItemFrame) event.getRightClicked();
		frame.setRotation(Rotation.NONE);
	}
	
}
 
Example 26
Project: EchoPet   File: WrappedEntityType.java   Source Code and License 5 votes vote down vote up
public EntityType get() {
    try {
        return EntityType.valueOf(this.entityTypeName);
    } catch (Exception exception) {
        return null;
    }
}
 
Example 27
Project: bskyblock   File: NMSHandler.java   Source Code and License 5 votes vote down vote up
@Override
public ItemStack getSpawnEgg(EntityType type, int amount) {
    ItemStack egg = new ItemStack(Material.MONSTER_EGG, amount);
    SpawnEggMeta spm = (SpawnEggMeta)egg.getItemMeta();
    spm.setSpawnedType(type);
    egg.setItemMeta(spm);
    return egg;
}
 
Example 28
Project: MT_Core   File: MobListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onBurn(EntityCombustEvent e) {
	if (e.getEntityType() == EntityType.ZOMBIE) {
		long time = e.getEntity().getWorld().getTime();
		if (e.getEntity().getLocation().getBlock().getLightFromSky() == 15 && time > 0 && time < 12000) {
			e.getEntity().setFireTicks(0);
			e.setDuration(0);
			e.setCancelled(true);
		}
	}
}
 
Example 29
Project: Kineticraft   File: Frilda.java   Source Code and License 5 votes vote down vote up
public Frilda(Dungeon d) {
    super(new Location(d.getWorld(), -5, 11, 56, 90, 0), EntityType.ZOMBIE, "Frilda", true);
    setGear(Material.STONE_SWORD, Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS);
    addStage(new MeleeAttack(5, 2)); // TODO: Fireball.
    addStage(.65, "Argh! How dare you! You're going to regret this!",
            new MeleeAttack(6, 2.75), new AttackFlameWheel());
}
 
Example 30
Project: SurvivalPlus   File: Chairs.java   Source Code and License 5 votes vote down vote up
private ArmorStand dropSeat(Block chair, Stairs stairs)
{
	Location location = chair.getLocation().add(0.5, (-0.7 - 0.5), 0.5);
	
	switch(stairs.getDescendingDirection())
	{
		case NORTH:
			location.setYaw(180);
			break;
		case EAST:
			location.setYaw(270);
			break;
		case SOUTH:
			location.setYaw(0);
			break;
		case WEST:
			location.setYaw(90);
		default:
	}
	
	ArmorStand drop = (ArmorStand)location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
	drop.setCustomName("Chair");
	drop.setVelocity(new Vector(0, 0, 0));
	drop.setGravity(false);
	drop.setVisible(false);
	
	return drop;
}
 
Example 31
Project: MultiLineAPI   File: Tag.java   Source Code and License 5 votes vote down vote up
public PacketContainer refreshName(Entity forWhat, Player forWho) {
    if (this.name == null) return null;
    this.name.setWatcher(createArmorStandWatcher(
            getName((forWhat.getCustomName() != null && forWhat.getType() != EntityType.PLAYER) ?
                    forWhat.getCustomName() : forWhat.getName(), forWhat, forWho),
            forWhat.isCustomNameVisible() || forWhat.getType().equals(EntityType.PLAYER)
    ));
    return PacketUtil.getMetadataPacket(name);
}
 
Example 32
Project: Kineticraft   File: Flight.java   Source Code and License 5 votes vote down vote up
/**
 * Is the player in a state or situation that we should deem them not flying?
 * @param player
 * @return immune
 */
private static boolean isImmune(Player player) {
    return player.getGameMode() != GameMode.SURVIVAL
            || Utils.getRank(player).isAtLeast(EnumRank.MEDIA) // Don't bypass this check.
            || player.isGliding() // Not using Elytra
            || player.hasPotionEffect(PotionEffectType.LEVITATION) // Doesn't have a levitation potion
            || player.getVehicle() != null // Not in a vehicle
            || player.getVelocity().getY() > 0 // Not being launched up
            || player.getNearbyEntities(1, 2, 1).stream().anyMatch(e -> e.getType() == EntityType.BOAT) // Not standing on a boat.
            || player.getLocation().getBlock().isLiquid(); // Not in water.
}
 
Example 33
Project: KingdomFactions   File: BlockPlace.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {

	if (event.getItemInHand().getType() != Material.MOB_SPAWNER)
		return;

	ItemStack is = event.getItemInHand();
	if (!is.hasItemMeta())
		return;

	ItemMeta im = is.getItemMeta();

	if (!im.hasLore())
		return;

	String lore = im.getLore().toString();

	if (!lore.contains("Spawner:"))
		return;

	EntityType entity = getEntity(lore);

	if (entity == EntityType.AREA_EFFECT_CLOUD) {
		event.setCancelled(true);
		return;
	}

	setSpawner(event.getBlock(), entity);
}
 
Example 34
Project: SurvivalPlus   File: ChickenSpawn.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onChickenSpawn(CreatureSpawnEvent e)
{
	if(e.getEntityType() == EntityType.CHICKEN)
	{
		if(e.getSpawnReason() == SpawnReason.BREEDING)
		{
			e.setCancelled(true);
			Random rand = new Random();
			Location loc = e.getLocation();
			loc.getWorld().dropItem(loc, new ItemStack(Material.EGG, rand.nextInt(4) + 1));
        	loc.getWorld().playSound(loc, Sound.ENTITY_CHICKEN_EGG, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
		}
	}
}
 
Example 35
Project: Hub   File: SonicSquid.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
    if (event.getEntity().getType() != EntityType.PLAYER)
        return;

    if (!this.hasPlayer((Player) event.getEntity()))
        return;

    event.getDismounted().setPassenger(event.getEntity());
}
 
Example 36
Project: Uranium   File: CraftCreatureSpawner.java   Source Code and License 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 37
Project: Uranium   File: CraftStatistic.java   Source Code and License 5 votes vote down vote up
public static net.minecraft.stats.StatBase getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
    EntityEggInfo entityEggInfo = (EntityEggInfo) EntityList.entityEggs.get(Integer.valueOf(entity.getTypeId()));

    if (entityEggInfo != null) {
        return entityEggInfo.field_151512_d;
    }
    return null;
}
 
Example 38
Project: SuperiorCraft   File: CustomBlockTexture.java   Source Code and License 5 votes vote down vote up
public ArmorStand placeBlock(Location l) {
	ArmorStand block = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
	block.setSmall(true);
	block.setGravity(false);
	block.setCustomName("CustomBlock");
	block.setCustomNameVisible(false);
	block.setInvulnerable(true);
	block.setVisible(false);
	block.setMarker(true);
	block.setSilent(true);
	
	ItemStack a = new ItemStack(Material.LEATHER_BOOTS);
	a.setDurability((short) primary.getTexture());
	LeatherArmorMeta am = (LeatherArmorMeta) a.getItemMeta();
	am.setColor(primary.getColor());
	am.setUnbreakable(true);
	if (primary.isGlowing()) {
		am.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
	}
	a.setItemMeta(am);
	block.setHelmet(a);
	
	if (secondary != null) {
		ItemStack b = new ItemStack(Material.LEATHER_BOOTS);
		b.setDurability((short) secondary.getTexture());
		LeatherArmorMeta bm = (LeatherArmorMeta) b.getItemMeta();
		bm.setColor(secondary.getColor());
		bm.setUnbreakable(true);
		if (secondary.isGlowing()) {
			System.out.println("H");
			bm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
		}
		b.setItemMeta(bm);
		block.getEquipment().setItemInMainHand(b);
	}
	
	return block;
}
 
Example 39
Project: bskyblock   File: IslandGuard1_9.java   Source Code and License 5 votes vote down vote up
/**
 * Handle interaction with end crystals 1.9
 *
 * @param e
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onHitEndCrystal(final PlayerInteractAtEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.9 " +e.getEventName());
    }
    if (!Util.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
        return;
    }
    if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ENDER_CRYSTAL)) {
        // Check island
        Island island = plugin.getIslands().getIslandAt(e.getRightClicked().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island !=null) {
            if (island.getMembers().contains(e.getPlayer().getUniqueId()) || island.getFlag(SettingsFlag.BREAK_BLOCKS)) {
                return;
            }
        }
        e.setCancelled(true);
        Util.sendMessage(e.getPlayer(), plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
    }
}
 
Example 40
Project: SurvivalAPI   File: SuperheroesModule.java   Source Code and License 5 votes vote down vote up
/**
 * Cancel fall damages
 *
 * @param event Event instance
 */
@EventHandler
public void onDamage(EntityDamageEvent event)
{
    if (event.getEntityType() == EntityType.PLAYER && event.getCause() == EntityDamageEvent.DamageCause.FALL)
    {
        event.setCancelled(true);
        event.setDamage(0);
    }
}