Search in sources :

Example 36 with ICombatManager

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

the class PlaceholderHelper method getInCombat.

public static String getInCombat(ICombatLogX plugin, Player player) {
    ICombatManager combatManager = plugin.getCombatManager();
    LanguageManager languageManager = plugin.getLanguageManager();
    boolean inCombat = combatManager.isInCombat(player);
    String key = ("placeholder.status." + (inCombat ? "in-combat" : "not-in-combat"));
    return languageManager.getMessage(player, key, null, true);
}
Also used : ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) LanguageManager(com.github.sirblobman.api.language.LanguageManager)

Example 37 with ICombatManager

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

the class PlaceholderHelper method getEnemyName.

public static String getEnemyName(ICombatLogX plugin, Player player) {
    ICombatManager combatManager = plugin.getCombatManager();
    LivingEntity enemy = combatManager.getEnemy(player);
    if (enemy == null)
        return getUnknownEnemy(plugin, player);
    MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
    EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
    return entityHandler.getName(enemy);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) EntityHandler(com.github.sirblobman.api.nms.EntityHandler)

Example 38 with ICombatManager

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

the class ActionBarUpdater method getBars.

private String getBars(Player player, long timeLeftMillis) {
    ConfigurationManager configurationManager = this.expansion.getConfigurationManager();
    YamlConfiguration configuration = configurationManager.get("config.yml");
    int scale = configuration.getInt("scale");
    String leftColorString = configuration.getString("left-color", "GREEN");
    String leftSymbol = configuration.getString("left-symbol", "|");
    String rightColorString = configuration.getString("right-color", "RED");
    String rightSymbol = configuration.getString("right-symbol", "|");
    ChatColor leftColor = getChatColor(leftColorString);
    ChatColor rightColor = getChatColor(rightColorString);
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = plugin.getCombatManager();
    double timerMaxMillis = (combatManager.getMaxTimerSeconds(player) * 1_000L);
    double progressPercent = ((double) timeLeftMillis / timerMaxMillis);
    long leftBarsCount = Math.round(scale * progressPercent);
    long rightBarsCount = (scale - leftBarsCount);
    StringBuilder builder = new StringBuilder();
    builder.append(leftColor);
    for (long i = 0; i < leftBarsCount; i++) {
        builder.append(leftSymbol);
    }
    builder.append(rightColor);
    for (long i = 0; i < rightBarsCount; i++) {
        builder.append(rightSymbol);
    }
    String barsString = builder.toString();
    return MessageUtility.color(barsString);
}
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) ChatColor(net.md_5.bungee.api.ChatColor)

Example 39 with ICombatManager

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

the class RegionHandler method preventEntry.

public final void preventEntry(Cancellable e, Player player, Location fromLocation, Location toLocation) {
    if (player == null) {
        return;
    }
    ICombatLogX plugin = this.expansion.getPlugin();
    JavaPlugin javaPlugin = plugin.getPlugin();
    ICombatManager combatManager = plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    LivingEntity enemy = combatManager.getEnemy(player);
    sendEntryDeniedMessage(player, enemy);
    NoEntryMode noEntryMode = getNoEntryMode();
    switch(noEntryMode) {
        case KILL_PLAYER:
            player.setHealth(0.0D);
            break;
        case TELEPORT_TO_ENEMY:
            if (enemy != null) {
                player.teleport(enemy);
                break;
            }
        case CANCEL_EVENT:
            e.setCancelled(true);
            break;
        case KNOCKBACK_PLAYER:
            if (player.isInsideVehicle()) {
                if (!player.leaveVehicle()) {
                    e.setCancelled(true);
                    break;
                }
            }
            Runnable task = () -> knockbackPlayer(player, fromLocation, toLocation);
            BukkitScheduler scheduler = Bukkit.getScheduler();
            scheduler.runTaskLater(javaPlugin, task, 1L);
            break;
        case DISABLED:
        case VULNERABLE:
        default:
            break;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) NoEntryMode(com.github.sirblobman.combatlogx.api.object.NoEntryMode) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 40 with ICombatManager

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

the class CommandCombatLogXTag method execute.

@Override
protected boolean execute(CommandSender sender, String[] args) {
    if (!checkPermission(sender, "combatlogx.command.combatlogx.tag", true)) {
        return true;
    }
    if (args.length < 1) {
        return false;
    }
    Player target = findTarget(sender, args[0]);
    if (target == null) {
        return true;
    }
    String targetName = target.getName();
    Replacer replacer = message -> message.replace("{target}", targetName);
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = plugin.getCombatManager();
    boolean successfulTag;
    if (args.length < 2) {
        successfulTag = combatManager.tag(target, null, TagType.UNKNOWN, TagReason.UNKNOWN);
    } else {
        BigInteger bigSeconds = parseInteger(sender, args[0]);
        if (bigSeconds == null) {
            return true;
        }
        long seconds = bigSeconds.longValue();
        long milliseconds = TimeUnit.SECONDS.toMillis(seconds);
        long systemMillis = System.currentTimeMillis();
        long combatEndTime = (systemMillis + milliseconds);
        successfulTag = combatManager.tag(target, null, TagType.UNKNOWN, TagReason.UNKNOWN, combatEndTime);
    }
    String messagePath = ("command.combatlogx." + (successfulTag ? "tag-player" : "tag-failure"));
    sendMessageWithPrefix(sender, messagePath, replacer, true);
    return true;
}
Also used : IntStream(java.util.stream.IntStream) CommandSender(org.bukkit.command.CommandSender) CombatLogCommand(com.github.sirblobman.combatlogx.api.command.CombatLogCommand) Set(java.util.Set) Player(org.bukkit.entity.Player) TagReason(com.github.sirblobman.combatlogx.api.object.TagReason) Collectors(java.util.stream.Collectors) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) TimeUnit(java.util.concurrent.TimeUnit) TagType(com.github.sirblobman.combatlogx.api.object.TagType) List(java.util.List) Replacer(com.github.sirblobman.api.language.Replacer) BigInteger(java.math.BigInteger) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) Collections(java.util.Collections) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) BigInteger(java.math.BigInteger) Replacer(com.github.sirblobman.api.language.Replacer) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

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