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;
}
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);
}
Aggregations