org.spongepowered.api.entity.living.monster.Monster Java Examples

The following examples show how to use org.spongepowered.api.entity.living.monster.Monster. 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: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - DamageEntityEvent event");

    Entity ent = e.getTargetEntity();
    Location<World> l = e.getTargetEntity().getLocation();

    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());
    if (r == null) return;

    if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {
        if (!r.canFire()) {
            e.setCancelled(true);
            return;
        }
    }

    if ((ent instanceof Boat || ent instanceof Minecart) && e.getCause().first(Player.class).isPresent()) {
        Player p = e.getCause().first(Player.class).get();
        if (!r.canMinecart(p)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak");
            e.setCancelled(true);
        }
    }
}
 
Example #2
Source File: MobSpawningListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener
public void onEntitySpawn(SpawnEntityEvent event)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	event.filterEntities(e -> !(e instanceof Monster) || DataHandler.getFlag("mobs", e.getLocation()));
}
 
Example #3
Source File: InteractPermListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractEntityEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Entity target = event.getTargetEntity();
	if (target instanceof Player || target instanceof Monster)
	{
		return;
	}
	if (target instanceof ItemFrame || target instanceof ArmorStand)
	{
		if (player.hasPermission("nations.admin.bypass.perm.build"))
		{
			return;
		}
		if (!DataHandler.getPerm("build", player.getUniqueId(), event.getTargetEntity().getLocation()))
		{
			event.setCancelled(true);
			player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
		}
		return;
	}
	if (!DataHandler.getPerm("interact", player.getUniqueId(), event.getTargetEntity().getLocation()))
	{
		event.setCancelled(true);
		player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
	}
}
 
Example #4
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) {
    if (e instanceof Monster) {
        BlockSnapshot b = event.getTransactions().get(0).getOriginal();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName());
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
        if (!cont.canWorldBreak(b)) {
            event.setCancelled(true);
            return;
        }
        if (r != null && !r.canMobLoot()) {
            event.setCancelled(true);
        }
    }
}
 
Example #5
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBurnGlobal(ChangeBlockEvent.Modify e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBurnGlobal event");

    Transaction<BlockSnapshot> b = e.getTransactions().get(0);

    if (e.getCause().first(Monster.class).isPresent()) {
        Region r = RedProtect.get().rm.getTopRegion(b.getOriginal().getLocation().get(), this.getClass().getName());
        if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getOriginal().getLocation().get().getExtent().getName()).use_minecart) {
            e.setCancelled(true);
        }
    }
}
 
Example #6
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEvent e, @Root Player p) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is InteractEvent event! Cancelled? " + false);
    if (!e.getInteractionPoint().isPresent()) {
        return;
    }
    Location<World> loc = new Location<>(p.getWorld(), e.getInteractionPoint().get());
    Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());

    if (!canUse(p, r)) {
        e.setCancelled(true);
        return;
    }

    if (r != null) {
        return;
    }

    if (e instanceof InteractBlockEvent) {
        BlockSnapshot blockSnapshot = ((InteractBlockEvent) e).getTargetBlock();
        if (RedProtect.get().config.needClaimToInteract(p, blockSnapshot)) {
            e.setCancelled(true);
            return;
        }
    }
    if (e instanceof InteractEntityEvent) {
        Entity ent = ((InteractEntityEvent) e).getTargetEntity();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener - Entity: " + ent.getType().getName());
        if (ent instanceof Minecart || ent instanceof Boat) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (ent instanceof Hanging || ent instanceof ArmorStand) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (ent instanceof Monster && !RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_monsters && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
        if (ent instanceof Animal || ent instanceof Golem || ent instanceof Ambient || ent instanceof Aquatic) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_passives && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if ((loc.getBlock().getType().equals(BlockTypes.PUMPKIN_STEM) ||
                loc.getBlock().getType().equals(BlockTypes.MELON_STEM) ||
                loc.getBlock().getType().getName().contains("chorus_") ||
                loc.getBlock().getType().getName().contains("beetroot_") ||
                loc.getBlock().getType().getName().contains("sugar_cane"))
                && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).allow_crop_trample && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            return;
        }
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).interact) {
            if (!p.hasPermission("redprotect.world.bypass") && !(ent instanceof Player)) {
                if (!canInteractEntitiesList(p.getWorld(), ent.getType().getName())) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }

    if (e instanceof InteractBlockEvent) {
        InteractBlockEvent eb = (InteractBlockEvent) e;
        String bname = eb.getTargetBlock().getState().getType().getName();
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Block: " + bname);
        if (bname.contains("rail") || bname.contains("water")) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
            }
        } else {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).interact) {
                if (!p.hasPermission("redprotect.world.bypass")) {
                    if (!canInteractBlocksList(p.getWorld(), bname)) {
                        e.setCancelled(true);
                        return;
                    }
                }
            }
            if ((!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass"))
                    && bname.contains("leaves")) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #7
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileHit(CollideEntityEvent event, @Root Projectile proj) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "Is CollideEntityEvent(onProjectileHit) event.");
    RedProtect.get().logger.debug(LogLevel.ENTITY, "Projectile: " + proj.getType().getName());
    if (RedProtect.get().rm.getTopRegion(proj.getLocation(), this.getClass().getName()) != null) return;

    for (Entity ent : event.getEntities()) {
        RedProtect.get().logger.debug(LogLevel.ENTITY, "Entity: " + ent.getType().getName());

        if (proj.getShooter() instanceof Player) {
            Player p = (Player) proj.getShooter();

            if (ent instanceof Player) {
                if (!p.equals(ent) && !RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).pvp && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Animal || ent instanceof Villager || ent instanceof Golem || ent instanceof Ambient) {
                if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).player_hurt_passives && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Monster) {
                if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).player_hurt_monsters && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                }
            }
        } else {
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).entity_block_damage) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example #8
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {

    for (Entity e : event.getEntities()) {
        if (e == null || (RedProtect.get().rm.getTopRegion(e.getLocation(), this.getClass().getName()) != null &&
                RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_allow_on_regions)) {
            continue;
        }

        //blacklist
        List<String> blacklist = RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_blacklist;
        if (e instanceof Monster && blacklist.contains("MONSTERS")) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED Monster " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && blacklist.contains("PASSIVES")) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED Animal " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if (blacklist.stream().anyMatch(e.getType().getName()::matches)) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED " + e.getType().getName());
            event.setCancelled(true);
            return;
        }

        //whitelist
        List<String> wtl = RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_whitelist;
        if (!wtl.isEmpty()) {
            if (e instanceof Monster && !wtl.contains("MONSTERS")) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED Monster " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
            if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && !wtl.contains("PASSIVES")) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED Animal " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
            if (wtl.stream().noneMatch(e.getType().getName()::matches)) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Spawn mob " + e.getType().getName());
    }
}