Search in sources :

Example 1 with PlayerReTagEvent

use of com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent in project CombatLogX by SirBlobman.

the class CombatManager method tag.

@Override
public boolean tag(Player player, LivingEntity enemy, TagType tagType, TagReason tagReason, long customEndMillis) {
    Validate.notNull(player, "player must not be null!");
    Validate.notNull(tagType, "tagType must not be null!");
    Validate.notNull(tagReason, "tagReason must not be null!");
    if (player.hasMetadata("NPC")) {
        return false;
    }
    if (failsPreTagEvent(player, enemy, tagType, tagReason)) {
        this.plugin.printDebug("The PlayerPreTagEvent was cancelled.");
        return false;
    }
    boolean alreadyInCombat = isInCombat(player);
    this.plugin.printDebug("Previous Combat Status: " + alreadyInCombat);
    PluginManager pluginManager = Bukkit.getPluginManager();
    if (alreadyInCombat) {
        PlayerReTagEvent event = new PlayerReTagEvent(player, enemy, tagType, tagReason, customEndMillis);
        pluginManager.callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        customEndMillis = event.getEndTime();
    } else {
        PlayerTagEvent event = new PlayerTagEvent(player, enemy, tagType, tagReason, customEndMillis);
        pluginManager.callEvent(event);
        customEndMillis = event.getEndTime();
        sendTagMessage(player, enemy, tagType, tagReason);
    }
    UUID uuid = player.getUniqueId();
    this.combatMap.put(uuid, customEndMillis);
    if (enemy != null) {
        this.enemyMap.put(uuid, enemy);
    }
    String playerName = player.getName();
    this.plugin.printDebug("Successfully put player '" + playerName + "' into combat.");
    return true;
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerReTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent) PlayerTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerTagEvent) UUID(java.util.UUID)

Aggregations

PlayerReTagEvent (com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent)1 PlayerTagEvent (com.github.sirblobman.combatlogx.api.event.PlayerTagEvent)1 UUID (java.util.UUID)1 PluginManager (org.bukkit.plugin.PluginManager)1