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

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#canPVP() . 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 onPlayerActivateSecAbility(SubSkillRandomCheckEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO SubSkillRandomCheckEvent event.");

    Player p = e.getPlayer();
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r == null) {
        return;
    }

    if (!r.canSkill(p)) {
        e.setCancelled(true);
    }
    if (!r.canPVP(p, null) && (e.getSkill().equals(PrimarySkillType.SWORDS) || e.getSkill().equals(PrimarySkillType.UNARMED) || e.getSkill().equals(PrimarySkillType.AXES))) {
        e.setCancelled(true);
    }
}
 
Example 2
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerUnarmed(McMMOPlayerDisarmEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO McMMOPlayerDisarmEvent event.");

    Player p = e.getPlayer();
    Region r = RedProtect.get().rm.getTopRegion(e.getDefender().getLocation());
    if (r == null) {
        return;
    }

    if (!r.canSkill(p)) {
        e.setCancelled(true);
    }
    if (!r.canPVP(p, e.getDefender()) && (e.getSkill().equals(PrimarySkillType.SWORDS) || e.getSkill().equals(PrimarySkillType.UNARMED) || e.getSkill().equals(PrimarySkillType.AXES))) {
        e.setCancelled(true);
    }
}
 
Example 3
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onSecondaryAbilityEvent(SubSkillEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO SecondaryAbilityEvent event.");

    Player p = e.getPlayer();
    Region r = RedProtect.get().rm.getTopRegion(e.getPlayer().getLocation());
    if (r == null) {
        return;
    }
    if (!r.canSkill(p)) {
        e.setCancelled(true);
    }
    if (!r.canPVP(p, null) && (e.getSkill().equals(PrimarySkillType.SWORDS) || e.getSkill().equals(PrimarySkillType.UNARMED) || e.getSkill().equals(PrimarySkillType.AXES))) {
        e.setCancelled(true);
    }
}
 
Example 4
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onFakeEntityDamageByEntityEvent(FakeEntityDamageByEntityEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO FakeEntityDamageByEntityEvent event.");

    if (e.getDamager() instanceof Player) {
        Player p = (Player) e.getDamager();
        Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());

        if (e.getEntity() instanceof Animals) {
            if (r != null && !r.canInteractPassives(p)) {
                RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpassive");
                e.setCancelled(true);
            }
        }

        if (e.getEntity() instanceof Player) {
            if (r != null && !r.canPVP(p, (Player) e.getEntity())) {
                RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpvp");
                e.setCancelled(true);
            }
        }
    }
}
 
Example 5
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onFakeEntityDamageEvent(FakeEntityDamageEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO FakeEntityDamageEvent event.");

    Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());

    if (e.getEntity() instanceof Animals) {
        if (r != null && !r.getFlagBool("passives")) {
            e.setCancelled(true);
        }
    }

    if (e.getEntity() instanceof Player) {
        Player p = (Player) e.getEntity();
        if (r != null && !r.canPVP(p, null)) {
            e.setCancelled(true);
        }
    }
}
 
Example 6
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerActivateAbility(McMMOPlayerAbilityActivateEvent e) {
    if (e.isCancelled()) {
        return;
    }

    RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO McMMOPlayerAbilityActivateEvent event.");

    Player p = e.getPlayer();

    //try to fix invisibility on bersek
    if (RedProtect.get().config.configRoot().hooks.mcmmo.fix_berserk_invisibility && e.getAbility().equals(SuperAbilityType.BERSERK)) {
        p.damage(0);
        for (Entity ent : p.getNearbyEntities(10, 10, 10)) {
            if (ent instanceof LivingEntity) {
                ((LivingEntity) ent).damage(0);
            }
        }
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r == null) {
        return;
    }

    if (!r.canSkill(p)) {
        p.sendMessage(RedProtect.get().lang.get("mcmmolistener.notallowed"));
        e.setCancelled(true);
    }
    if (!r.canPVP(p, null) && (e.getSkill().equals(PrimarySkillType.SWORDS) || e.getSkill().equals(PrimarySkillType.UNARMED))) {
        e.setCancelled(true);
    }
}
 
Example 7
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PotionSplashEvent");

    ProjectileSource thrower = event.getPotion().getShooter();
    for (PotionEffect e : event.getPotion().getEffects()) {
        PotionEffectType t = e.getType();
        if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
            return;
        }
    }
    Player shooter;
    if (thrower instanceof Player) {
        shooter = (Player) thrower;
    } else {
        return;
    }
    for (Entity e2 : event.getAffectedEntities()) {
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (event.getEntity() instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
                event.setCancelled(true);
                return;
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example 8
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) {
    Player p = null;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is EntityDamageByEntityEvent event");

    if (e.getDamager() instanceof Player) {
        p = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
            p = (Player) proj.getShooter();
        }
    }

    if (p != null) {
        RedProtect.get().logger.debug(LogLevel.PLAYER, "Player: " + p.getName());
    } else {
        RedProtect.get().logger.debug(LogLevel.PLAYER, "Player: is null");
        return;
    }

    RedProtect.get().logger.debug(LogLevel.PLAYER, "Damager: " + e.getDamager().getType().name());

    Location l = e.getEntity().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r == null) {
        return;
    }

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

    if (e.getEntity() instanceof Player && !p.equals(e.getEntity()) && r.flagExists("pvp") && !r.canPVP((Player) e.getEntity(), p)) {
        RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpvp");
        e.setCancelled(true);
    }

    if ((e.getEntity() instanceof Hanging || e.getEntity() instanceof EnderCrystal) && !r.canBuild(p) && !r.canBreak(e.getEntityType())) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantremove");
        e.setCancelled(true);
    }

    if ((e.getEntity() instanceof Boat || e.getEntity() instanceof Minecart) && !r.canMinecart(p)) {
        RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak");
        e.setCancelled(true);
    }
}