Java Code Examples for br.net.fabiozumbi12.RedProtect.Bukkit.Region#canDeath()

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#canDeath() . 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: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerExperience(McMMOPlayerXpGainEvent event) {
    if (event.isCancelled()) {
        return;
    }

    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO McMMOPlayerXpGainEvent event. Skill " + event.getSkill().name());

    Player player = event.getPlayer();
    Region region = RedProtect.get().rm.getTopRegion(player.getLocation());
    if (region == null) {
        return;
    }

    if (!region.canSkill(player)) {
        event.setCancelled(true);
    }

    if (RedProtect.get().config.configRoot().hooks.mcmmo.fix_acrobatics_fire_leveling && event.getSkill().equals(PrimarySkillType.ACROBATICS) && (!region.canFire() || !region.canDeath())) {
        event.setCancelled(true);
    }
}
 
Example 2
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent e) {
    if (!(e.getEntity() instanceof Player)) {
        return;
    }

    Player play = (Player) e.getEntity();

    if (RedProtect.get().tpWait.contains(play.getName())) {
        RedProtect.get().tpWait.remove(play.getName());
        RedProtect.get().lang.sendMessage(e.getEntity(), RedProtect.get().lang.get("cmdmanager.region.tpcancelled"));
    }

    //deny damagecauses
    List<String> Causes = RedProtect.get().config.globalFlagsRoot().worlds.get(play.getWorld().getName()).deny_death_by;
    if (Causes.size() > 0) {
        for (String cause : Causes) {
            cause = cause.toUpperCase();
            try {
                if (e.getCause().equals(DamageCause.valueOf(cause))) {
                    e.setCancelled(true);
                }
            } catch (IllegalArgumentException ex) {
                RedProtect.get().logger.severe("The config 'deny_death_by' have an unknown damage cause type. Change to a valid damage cause type.");
            }
        }
    }

    Map<String, String> causeCommand = RedProtect.get().config.globalFlagsRoot().worlds.get(play.getWorld().getName()).command_on_damage;
    if (causeCommand.containsKey(e.getCause().name())) {
        String cmd = causeCommand.get(e.getCause().name())
                .replace("{player}", play.getName())
                .replace("{damage}", e.getCause().name());
        Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
        RedProtect.get().logger.info("Player " + play.getName() + " damaged by " + e.getCause().name() + " - Running command:\n - Command: " + cmd);
    }

    Region r = RedProtect.get().rm.getTopRegion(play.getLocation());
    if (r != null) {
        if (!r.canPlayerDamage()) {
            e.setCancelled(true);
        }
        //execute on health
        if (r.cmdOnHealth(play)) {
            RedProtect.get().logger.debug(LogLevel.PLAYER, "Cmd on healt: true");
        }

        if (!r.canDeath() && play.getHealth() <= 1) {
            e.setCancelled(true);
        }
    }
}