Search in sources :

Example 1 with ICombatManager

use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.

the class ForceFieldAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(PacketEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    World world = player.getWorld();
    PacketContainer packetContainer = e.getPacket();
    Location location = getLocation0(world, packetContainer);
    if (location == null) {
        return;
    }
    if (isForceFieldBlock(player, location)) {
        PacketType packetType = packetContainer.getType();
        if (packetType == Client.BLOCK_DIG) {
            StructureModifier<PlayerDigType> playerDigTypeModifier = packetContainer.getPlayerDigTypes();
            PlayerDigType playerDigType = playerDigTypeModifier.readSafely(0);
            GameMode gameMode = player.getGameMode();
            if (playerDigType == PlayerDigType.STOP_DESTROY_BLOCK || (playerDigType == PlayerDigType.START_DESTROY_BLOCK && gameMode == GameMode.CREATIVE)) {
                this.forceFieldListener.sendForceField(player, location);
            }
        }
        if (packetType == Client.USE_ITEM) {
            this.forceFieldListener.sendForceField(player, location);
        }
    }
}
Also used : GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) PlayerDigType(com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) PacketType(com.comphenix.protocol.PacketType) World(org.bukkit.World) Location(org.bukkit.Location)

Example 2 with ICombatManager

use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.

the class ForceFieldAdapter method onPacketSending.

@Override
public void onPacketSending(PacketEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    World world = player.getWorld();
    PacketContainer packetContainer = e.getPacket();
    Location location = getLocation0(world, packetContainer);
    if (isForceFieldBlock(player, location)) {
        WrappedBlockData wrappedBlockData = getWrappedBlockData();
        if (wrappedBlockData != null) {
            packetContainer.getBlockData().writeSafely(0, wrappedBlockData);
        }
    }
}
Also used : WrappedBlockData(com.comphenix.protocol.wrappers.WrappedBlockData) Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) World(org.bukkit.World) Location(org.bukkit.Location)

Example 3 with ICombatManager

use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.

the class ListenerForceField method isSafe.

protected boolean isSafe(Player player, Location location) {
    ICombatManager combatManager = getCombatManager();
    LivingEntity enemy = combatManager.getEnemy(player);
    TagType tagType = getTagType(enemy);
    return isSafe(player, location, tagType);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) TagType(com.github.sirblobman.combatlogx.api.object.TagType) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager)

Example 4 with ICombatManager

use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.

the class ListenerDamage method onDamage.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
    Entity entity = e.getEntity();
    if (!(entity instanceof Player))
        return;
    if (checkDamageByEntity(e))
        return;
    Player player = (Player) entity;
    DamageCause damageCause = e.getCause();
    if (isDisabled(damageCause))
        return;
    ICombatLogX combatLogX = getCombatLogX();
    ICombatManager combatManager = combatLogX.getCombatManager();
    boolean wasInCombat = combatManager.isInCombat(player);
    boolean tagged = combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
    if (tagged && !wasInCombat)
        sendMessage(player, damageCause);
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ICombatManager

use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.

the class ListenerMythicMobs method onDamage.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) {
    Entity damaged = e.getEntity();
    Entity damager = e.getDamager();
    ICombatManager combatManager = getCombatManager();
    if (damaged instanceof Player && damager instanceof LivingEntity && isMythicMob(damager)) {
        String mobName = getMythicMobName(damager);
        if (isForceTag(mobName)) {
            Player playerDamaged = (Player) damaged;
            LivingEntity livingDamager = (LivingEntity) damager;
            combatManager.tag(playerDamaged, livingDamager, TagType.MYTHIC_MOB, TagReason.ATTACKED);
        }
    }
    if (damager instanceof Player && damaged instanceof LivingEntity && isMythicMob(damaged)) {
        String mobName = getMythicMobName(damaged);
        if (isForceTag(mobName)) {
            Player playerDamager = (Player) damager;
            LivingEntity livingDamaged = (LivingEntity) damaged;
            combatManager.tag(playerDamager, livingDamaged, TagType.MYTHIC_MOB, TagReason.ATTACKER);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)56 Player (org.bukkit.entity.Player)29 LivingEntity (org.bukkit.entity.LivingEntity)24 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)19 EventHandler (org.bukkit.event.EventHandler)9 Location (org.bukkit.Location)8 LanguageManager (com.github.sirblobman.api.language.LanguageManager)7 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)7 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)5 TagType (com.github.sirblobman.combatlogx.api.object.TagType)5 Entity (org.bukkit.entity.Entity)5 Replacer (com.github.sirblobman.api.language.Replacer)4 DecimalFormat (java.text.DecimalFormat)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 EntityType (org.bukkit.entity.EntityType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)2