Search in sources :

Example 1 with PlayerTagEvent

use of com.github.sirblobman.combatlogx.api.event.PlayerTagEvent 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)

Example 2 with PlayerTagEvent

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

the class ListenerGameMode method onTag.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
    if (!shouldForceSwitch())
        return;
    GameMode gameMode = getForceSwitchMode();
    Player player = e.getPlayer();
    player.setGameMode(gameMode);
    String gameModeName = gameMode.name();
    Replacer replacer = message -> message.replace("{game_mode}", gameModeName);
    sendMessage(player, "expansion.cheat-prevention.game-mode.force-switch", replacer);
}
Also used : PlayerGameModeChangeEvent(org.bukkit.event.player.PlayerGameModeChangeEvent) PlayerTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerTagEvent) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) Player(org.bukkit.entity.Player) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) EventHandler(org.bukkit.event.EventHandler) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) GameMode(org.bukkit.GameMode) EventPriority(org.bukkit.event.EventPriority) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) Replacer(com.github.sirblobman.api.language.Replacer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PlayerTagEvent (com.github.sirblobman.combatlogx.api.event.PlayerTagEvent)2 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)1 Replacer (com.github.sirblobman.api.language.Replacer)1 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 PlayerReTagEvent (com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent)1 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)1 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)1 UntagReason (com.github.sirblobman.combatlogx.api.object.UntagReason)1 UUID (java.util.UUID)1 GameMode (org.bukkit.GameMode)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 EventPriority (org.bukkit.event.EventPriority)1 PlayerGameModeChangeEvent (org.bukkit.event.player.PlayerGameModeChangeEvent)1 PluginManager (org.bukkit.plugin.PluginManager)1