Search in sources :

Example 1 with NoEntryMode

use of com.github.sirblobman.combatlogx.api.object.NoEntryMode in project CombatLogX by SirBlobman.

the class RegionVulnerableListener method onDamage.

@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent e) {
    RegionHandler regionHandler = this.regionExpansion.getRegionHandler();
    NoEntryMode noEntryMode = regionHandler.getNoEntryMode();
    if (noEntryMode != NoEntryMode.VULNERABLE)
        return;
    Entity damaged = e.getEntity();
    Player player = getPlayerOrPassenger(damaged);
    if (player == null)
        return;
    if (isInCombat(player)) {
        ICombatManager combatManager = getCombatManager();
        LivingEntity enemy = combatManager.getEnemy(player);
        TagType tagType = getTagType(enemy);
        Location location = player.getLocation();
        if (regionHandler.isSafeZone(player, location, tagType)) {
            e.setCancelled(false);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) TagType(com.github.sirblobman.combatlogx.api.object.TagType) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) NoEntryMode(com.github.sirblobman.combatlogx.api.object.NoEntryMode) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with NoEntryMode

use of com.github.sirblobman.combatlogx.api.object.NoEntryMode in project CombatLogX by SirBlobman.

the class RegionHandler method preventEntry.

public final void preventEntry(Cancellable e, Player player, Location fromLocation, Location toLocation) {
    if (player == null) {
        return;
    }
    ICombatLogX plugin = this.expansion.getPlugin();
    JavaPlugin javaPlugin = plugin.getPlugin();
    ICombatManager combatManager = plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    LivingEntity enemy = combatManager.getEnemy(player);
    sendEntryDeniedMessage(player, enemy);
    NoEntryMode noEntryMode = getNoEntryMode();
    switch(noEntryMode) {
        case KILL_PLAYER:
            player.setHealth(0.0D);
            break;
        case TELEPORT_TO_ENEMY:
            if (enemy != null) {
                player.teleport(enemy);
                break;
            }
        case CANCEL_EVENT:
            e.setCancelled(true);
            break;
        case KNOCKBACK_PLAYER:
            if (player.isInsideVehicle()) {
                if (!player.leaveVehicle()) {
                    e.setCancelled(true);
                    break;
                }
            }
            Runnable task = () -> knockbackPlayer(player, fromLocation, toLocation);
            BukkitScheduler scheduler = Bukkit.getScheduler();
            scheduler.runTaskLater(javaPlugin, task, 1L);
            break;
        case DISABLED:
        case VULNERABLE:
        default:
            break;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) NoEntryMode(com.github.sirblobman.combatlogx.api.object.NoEntryMode) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Aggregations

ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)2 NoEntryMode (com.github.sirblobman.combatlogx.api.object.NoEntryMode)2 LivingEntity (org.bukkit.entity.LivingEntity)2 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 TagType (com.github.sirblobman.combatlogx.api.object.TagType)1 Location (org.bukkit.Location)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)1 BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)1