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
}
}
}
}
}
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;
}
}
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;
}
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;
}
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);
}
}
}
Aggregations