Search in sources :

Example 76 with EntityType

use of org.bukkit.entity.EntityType in project acidisland by tastybento.

the class IslandGuard method onSpawnerBlockPlace.

/**
 * Sets spawners to their type
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSpawnerBlockPlace(final BlockPlaceEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: block place");
    if (inWorld(e.getPlayer()) && Util.playerIsHolding(e.getPlayer(), Material.MOB_SPAWNER)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: in world");
        // Get item in hand
        for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
            if (item.getType().equals(Material.MOB_SPAWNER) && item.hasItemMeta() && item.getItemMeta().hasLore()) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: spawner in hand with lore");
                List<String> lore = item.getItemMeta().getLore();
                if (!lore.isEmpty()) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: lore is not empty");
                    for (EntityType type : EntityType.values()) {
                        if (lore.get(0).equals(Util.prettifyText(type.name()))) {
                            // Found the spawner type
                            if (DEBUG)
                                plugin.getLogger().info("DEBUG: found type");
                            e.getBlock().setType(Material.MOB_SPAWNER);
                            CreatureSpawner cs = (CreatureSpawner) e.getBlock().getState();
                            cs.setSpawnedType(type);
                        }
                    }
                // Spawner type not found - do anything : it may be another plugin's spawner
                }
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ItemStack(org.bukkit.inventory.ItemStack) CreatureSpawner(org.bukkit.block.CreatureSpawner) EventHandler(org.bukkit.event.EventHandler)

Example 77 with EntityType

use of org.bukkit.entity.EntityType in project acidisland by tastybento.

the class IslandGuard method onExplosion.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
    if (DEBUG) {
    // Commented out due to Ender dragon spam in Paper Spigot
    // plugin.getLogger().info(e.getEventName());
    // plugin.getLogger().info("Entity exploding is " + e.getEntity());
    }
    if (!inWorld(e.getLocation())) {
        return;
    }
    // Find out what is exploding
    Entity expl = e.getEntity();
    if (expl == null) {
        // Note player can still die from beds exploding in the nether.
        if (!Settings.allowTNTDamage) {
            // plugin.getLogger().info("TNT block damage prevented");
            e.blockList().clear();
        } else {
            if (!Settings.allowChestDamage) {
                List<Block> toberemoved = new ArrayList<>();
                // Save the chest blocks in a list
                for (Block b : e.blockList()) {
                    switch(b.getType()) {
                        case CHEST:
                        case ENDER_CHEST:
                        case STORAGE_MINECART:
                        case TRAPPED_CHEST:
                            toberemoved.add(b);
                            break;
                        default:
                            break;
                    }
                }
                // Now delete them
                for (Block b : toberemoved) {
                    e.blockList().remove(b);
                }
            }
        }
        return;
    }
    // prevent at spawn
    if (plugin.getGrid().isAtSpawn(e.getLocation())) {
        e.setCancelled(true);
    }
    // Find out what is exploding
    EntityType exploding = e.getEntityType();
    if (exploding == null) {
        return;
    }
    switch(exploding) {
        case CREEPER:
            if (!Settings.allowCreeperDamage) {
                // plugin.getLogger().info("Creeper block damage prevented");
                e.blockList().clear();
            } else {
                // Check if creeper griefing is allowed
                if (!Settings.allowCreeperGriefing) {
                    // Find out who the creeper was targeting
                    Creeper creeper = (Creeper) e.getEntity();
                    if (creeper.getTarget() instanceof Player) {
                        Player target = (Player) creeper.getTarget();
                        // Check if the target is on their own island or not
                        if (!plugin.getGrid().locationIsOnIsland(target, e.getLocation())) {
                            // They are a visitor tsk tsk
                            // Stop the blocks from being damaged, but allow hurt still
                            e.blockList().clear();
                        }
                    }
                    // Check if this creeper was lit by a visitor
                    if (litCreeper.contains(creeper.getUniqueId())) {
                        if (DEBUG) {
                            plugin.getLogger().info("DBEUG: preventing creeper from damaging");
                        }
                        litCreeper.remove(creeper.getUniqueId());
                        e.setCancelled(true);
                        return;
                    }
                }
                if (!Settings.allowChestDamage) {
                    List<Block> toberemoved = new ArrayList<Block>();
                    // Save the chest blocks in a list
                    for (Block b : e.blockList()) {
                        switch(b.getType()) {
                            case CHEST:
                            case ENDER_CHEST:
                            case STORAGE_MINECART:
                            case TRAPPED_CHEST:
                                toberemoved.add(b);
                                break;
                            default:
                                break;
                        }
                    }
                    // Now delete them
                    for (Block b : toberemoved) {
                        e.blockList().remove(b);
                    }
                }
            }
            break;
        case PRIMED_TNT:
        case MINECART_TNT:
            if (!Settings.allowTNTDamage) {
                // plugin.getLogger().info("TNT block damage prevented");
                e.blockList().clear();
            } else {
                if (!Settings.allowChestDamage) {
                    List<Block> toberemoved = new ArrayList<Block>();
                    // Save the chest blocks in a list
                    for (Block b : e.blockList()) {
                        switch(b.getType()) {
                            case CHEST:
                            case ENDER_CHEST:
                            case STORAGE_MINECART:
                            case TRAPPED_CHEST:
                                toberemoved.add(b);
                                break;
                            default:
                                break;
                        }
                    }
                    // Now delete them
                    for (Block b : toberemoved) {
                        e.blockList().remove(b);
                    }
                }
            }
            break;
        default:
            break;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) EventHandler(org.bukkit.event.EventHandler)

Example 78 with EntityType

use of org.bukkit.entity.EntityType in project InfernalMobs by NyaaCat.

the class CustomMobConfig method determineCustom.

public CustomMob determineCustom(LivingEntity event, int level, boolean isAutoSpawn) {
    EntityType type = event.getType();
    if (mobs.isEmpty())
        return null;
    for (Map.Entry<String, CustomMob> entry : mobs.entrySet()) {
        CustomMob customMob = entry.getValue();
        if (isAutoSpawn && !customMob.canAutoSpawn)
            continue;
        if (type.equals(EntityType.valueOf(customMob.type.toUpperCase()))) {
            boolean valid = customMob.inLevelRange(level) && (!isAutoSpawn || random(customMob.spawnChance));
            if (valid) {
                CustomMob mob = new CustomMob(customMob);
                mob.spawnLevel = level;
                return mob;
            }
        }
    }
    return null;
}
Also used : EntityType(org.bukkit.entity.EntityType)

Example 79 with EntityType

use of org.bukkit.entity.EntityType in project InfernalMobs by NyaaCat.

the class ConfigReader method getEnabledEntityTypes.

public static List<EntityType> getEnabledEntityTypes() {
    List<EntityType> ret = new ArrayList<>();
    for (String str : cfg().getStringList("enabledmobs")) {
        try {
            EntityType type = EntityType.valueOf(str);
            if (!type.isAlive() || !type.isSpawnable())
                throw new RuntimeException();
            ret.add(type);
        } catch (Exception ex) {
            InfernalMobs.instance.getLogger().warning(str + " is not a valid infernal mob type");
        }
    }
    return ret;
}
Also used : EntityType(org.bukkit.entity.EntityType) ArrayList(java.util.ArrayList)

Example 80 with EntityType

use of org.bukkit.entity.EntityType in project BKCommonLib by bergerhealer.

the class CreaturePreSpawnHandler_Paper method onCreaturePreSpawnEvent.

/**
 * This callback is called by a generated event listener to handle the event.
 * In future, please just add a dependency for paper api...
 *
 * TODO: FIXME!
 *
 * @param event
 */
public void onCreaturePreSpawnEvent(Object event) {
    if (!handle.isCancelled(event)) {
        Location at = handle.getLocation(event);
        EntityType entityType = handle.getEntityType(event);
        if (!CommonPlugin.getInstance().getEventFactory().handleCreaturePreSpawn(at, entityType)) {
            handle.abort(event);
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Location(org.bukkit.Location)

Aggregations

EntityType (org.bukkit.entity.EntityType)109 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 Material (org.bukkit.Material)23 Player (org.bukkit.entity.Player)23 Entity (org.bukkit.entity.Entity)19 Location (org.bukkit.Location)17 IOException (java.io.IOException)16 File (java.io.File)13 LivingEntity (org.bukkit.entity.LivingEntity)13 EventHandler (org.bukkit.event.EventHandler)12 PotionType (org.bukkit.potion.PotionType)12 HashMap (java.util.HashMap)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 Block (org.bukkit.block.Block)8 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 World (org.bukkit.World)7 SpawnEgg (org.bukkit.material.SpawnEgg)7 UUID (java.util.UUID)5 Biome (org.bukkit.block.Biome)5