Search in sources :

Example 6 with ICombatManager

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

the class HookMVdWPlaceholderAPI method getEnemyPlaceholder.

private String getEnemyPlaceholder(Player player, String enemyPlaceholder) {
    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager combatManager = plugin.getCombatManager();
    LivingEntity enemy = combatManager.getEnemy(player);
    if (enemy instanceof Player) {
        Player playerEnemy = (Player) enemy;
        String placeholder = String.format(Locale.US, "{%s}", enemyPlaceholder);
        return PlaceholderAPI.replacePlaceholders(playerEnemy, placeholder);
    }
    return getUnknownEnemy(plugin, player);
}
Also used : 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)

Example 7 with ICombatManager

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

the class ListenerDamage method checkTag.

private void checkTag(Entity entity, Entity enemy, TagReason tagReason) {
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = getCombatManager();
    plugin.printDebug("Checking if the entity '" + getName(entity) + "' should be tagged " + "for reason '" + tagReason + "' by enemy '" + getName(enemy) + "'.");
    if (!(entity instanceof Player)) {
        plugin.printDebug("Entity was not a player.");
        return;
    }
    if (!(enemy instanceof Player)) {
        plugin.printDebug("Enemy was not a player.");
        return;
    }
    Player playerEntity = (Player) entity;
    Player playerEnemy = (Player) enemy;
    plugin.printDebug("Triggering tag for player " + getName(playerEntity) + " with enemy " + getName(playerEnemy) + "...");
    boolean tag = combatManager.tag(playerEntity, playerEnemy, TagType.PLAYER, tagReason);
    plugin.printDebug("Tag Status: " + tag);
}
Also used : Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 8 with ICombatManager

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

the class ListenerUntag method runUntagCommands.

private void runUntagCommands(Player player, LivingEntity previousEnemy) {
    ConfigurationManager configurationManager = getPluginConfigurationManager();
    YamlConfiguration configuration = configurationManager.get("commands.yml");
    List<String> untagCommandList = configuration.getStringList("untag-command-list");
    if (untagCommandList.isEmpty()) {
        return;
    }
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = getCombatManager();
    for (String untagCommand : untagCommandList) {
        String replacedCommand = combatManager.replaceVariables(player, previousEnemy, untagCommand);
        if (replacedCommand.startsWith("[PLAYER]")) {
            String command = replacedCommand.substring("[PLAYER]".length());
            CommandHelper.runAsPlayer(plugin, player, command);
            continue;
        }
        if (replacedCommand.startsWith("[OP]")) {
            String command = replacedCommand.substring("[OP]".length());
            CommandHelper.runAsOperator(plugin, player, command);
            continue;
        }
        CommandHelper.runAsConsole(plugin, replacedCommand);
    }
}
Also used : ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager)

Example 9 with ICombatManager

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

the class ListenerUntag method onKick.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onKick(PlayerKickEvent e) {
    Player player = e.getPlayer();
    if (!isInCombat(player)) {
        return;
    }
    String kickReason = e.getReason();
    UntagReason untagReason = (isKickReasonIgnored(kickReason) ? UntagReason.EXPIRE : UntagReason.KICK);
    ICombatManager combatManager = getCombatManager();
    combatManager.untag(player, untagReason);
}
Also used : Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) EventHandler(org.bukkit.event.EventHandler)

Example 10 with ICombatManager

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

the class ListenerUntag method onQuit.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onQuit(PlayerQuitEvent e) {
    Player player = e.getPlayer();
    if (!isInCombat(player)) {
        return;
    }
    ICombatManager combatManager = getCombatManager();
    combatManager.untag(player, UntagReason.QUIT);
}
Also used : 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