Search in sources :

Example 11 with Replacer

use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.

the class CombatManager method sendTagMessage.

private void sendTagMessage(Player player, LivingEntity enemy, TagType tagType, TagReason tagReason) {
    if (tagType == TagType.DAMAGE) {
        return;
    }
    String enemyName = getEntityName(player, enemy);
    String enemyType = getEntityType(player, enemy);
    String tagReasonString = tagReason.name().toLowerCase(Locale.US);
    String tagTypeString = tagType.name().toLowerCase(Locale.US);
    Replacer replacer = message -> message.replace("{enemy}", enemyName).replace("{mob_type}", enemyType);
    String languagePath = ("tagged." + tagReasonString + "." + tagTypeString);
    this.plugin.sendMessageWithPrefix(player, languagePath, replacer, true);
}
Also used : PlayerTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerTagEvent) PlayerReTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) Player(org.bukkit.entity.Player) EntityHandler(com.github.sirblobman.api.nms.EntityHandler) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ITimerManager(com.github.sirblobman.combatlogx.api.manager.ITimerManager) Validate(com.github.sirblobman.api.utility.Validate) Replacer(com.github.sirblobman.api.language.Replacer) Locale(java.util.Locale) Map(java.util.Map) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) Bukkit(org.bukkit.Bukkit) PlayerPreTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerPreTagEvent) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) TagReason(com.github.sirblobman.combatlogx.api.object.TagReason) Collectors(java.util.stream.Collectors) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) OfflinePlayer(org.bukkit.OfflinePlayer) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) TagType(com.github.sirblobman.combatlogx.api.object.TagType) List(java.util.List) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlaceholderHelper(com.github.sirblobman.combatlogx.api.utility.PlaceholderHelper) Entry(java.util.Map.Entry) LanguageManager(com.github.sirblobman.api.language.LanguageManager) TimerType(com.github.sirblobman.combatlogx.api.object.TimerType) PluginManager(org.bukkit.plugin.PluginManager) Replacer(com.github.sirblobman.api.language.Replacer)

Example 12 with Replacer

use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.

the class CommandCombatTimer method checkOther.

private void checkOther(Player player, Player target) {
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = plugin.getCombatManager();
    LanguageManager languageManager = getLanguageManager();
    if (combatManager.isInCombat(target)) {
        double timeLeftMillis = combatManager.getTimerLeftMillis(target);
        double timeLeftSeconds = (timeLeftMillis / 1_000.0D);
        String decimalFormatString = languageManager.getMessage(player, "decimal-format", null, false);
        DecimalFormat decimalFormat = new DecimalFormat(decimalFormatString);
        String timeLeftString = decimalFormat.format(timeLeftSeconds);
        Replacer replacer = message -> message.replace("{time_left}", timeLeftString);
        sendMessageWithPrefix(player, "command.combat-timer.time-left-other", replacer, true);
        return;
    }
    sendMessageWithPrefix(player, "error.target-not-in-combat", null, true);
}
Also used : List(java.util.List) Replacer(com.github.sirblobman.api.language.Replacer) DecimalFormat(java.text.DecimalFormat) LanguageManager(com.github.sirblobman.api.language.LanguageManager) Set(java.util.Set) CombatLogPlayerCommand(com.github.sirblobman.combatlogx.api.command.CombatLogPlayerCommand) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) Collections(java.util.Collections) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) DecimalFormat(java.text.DecimalFormat) LanguageManager(com.github.sirblobman.api.language.LanguageManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Replacer(com.github.sirblobman.api.language.Replacer)

Example 13 with Replacer

use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.

the class ListenerLootProtection method onEntityItemPickup.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityItemPickup(EntityPickupItemEvent e) {
    Item itemEntity = e.getItem();
    if (!contains(itemEntity)) {
        return;
    }
    Entity entity = e.getEntity();
    if (!(entity instanceof Player)) {
        e.setCancelled(true);
        return;
    }
    Player player = (Player) entity;
    UUID itemEntityId = itemEntity.getUniqueId();
    ProtectedItem protectedItem = this.protectedItemMap.get(itemEntityId);
    UUID playerId = player.getUniqueId();
    QueryPickupEvent queryPickupEvent = new QueryPickupEvent(player, protectedItem);
    Bukkit.getPluginManager().callEvent(queryPickupEvent);
    if (!protectedItem.getOwnerUUID().equals(playerId) && !queryPickupEvent.isCancelled()) {
        e.setCancelled(true);
        if (!this.messageCooldownSet.contains(playerId)) {
            long expireMillisLeft = this.protectedItemMap.getExpectedExpiration(itemEntityId);
            long expireSecondsLeft = TimeUnit.MILLISECONDS.toSeconds(expireMillisLeft);
            String timeLeft = Long.toString(expireSecondsLeft);
            Replacer replacer = message -> message.replace("{time}", timeLeft);
            sendMessageWithPrefix(player, "expansion.loot-protection.protected", replacer, true);
            this.messageCooldownSet.add(playerId);
        }
    }
}
Also used : QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) Item(org.bukkit.entity.Item) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) ExpansionListener(com.github.sirblobman.combatlogx.api.expansion.ExpansionListener) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) Player(org.bukkit.entity.Player) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) EventHandler(org.bukkit.event.EventHandler) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) Location(org.bukkit.Location) Replacer(com.github.sirblobman.api.language.Replacer) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Bukkit(org.bukkit.Bukkit) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PlayerPunishEvent(com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent) Entity(org.bukkit.entity.Entity) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Set(java.util.Set) UUID(java.util.UUID) LivingEntity(org.bukkit.entity.LivingEntity) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Item(org.bukkit.entity.Item) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) Replacer(com.github.sirblobman.api.language.Replacer) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 14 with Replacer

use of com.github.sirblobman.api.language.Replacer in project CombatLogX by SirBlobman.

the class ListenerLootProtection method onDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent e) {
    LivingEntity entity = e.getEntity();
    ICombatLogX combatLogX = getCombatLogX();
    IDeathListener deathListener = combatLogX.getDeathListener();
    YamlConfiguration configuration = getExpansionConfigurationManager().get("config.yml");
    if (entity instanceof Player) {
        Player player = (Player) entity;
        if (configuration.getBoolean("only-protect-after-log", false) && !deathListener.contains(player)) {
            return;
        }
    }
    UUID entityId = entity.getUniqueId();
    UUID enemyId = this.enemyMap.get(entityId);
    if (!checkVoidKill(e) && entity instanceof Player) {
        Player player = (Player) entity;
        PlayerDataManager playerDataManager = getPlayerDataManager();
        YamlConfiguration playerData = playerDataManager.get(player);
        String enemyIdString = playerData.getString("loot-protection-enemy");
        if (enemyIdString != null) {
            playerData.set("loot-protection-enemy", null);
            playerDataManager.save(player);
            enemyId = UUID.fromString(enemyIdString);
        }
    }
    if (enemyId == null) {
        return;
    }
    Entity enemy = Bukkit.getEntity(enemyId);
    if (enemy == null) {
        return;
    }
    enemyId = enemy.getUniqueId();
    WorldXYZ entityLocation = WorldXYZ.from(entity);
    ConcurrentLinkedQueue<ProtectedItem> protectedItemQueue = new ConcurrentLinkedQueue<>();
    List<ItemStack> dropList = e.getDrops();
    for (ItemStack drop : dropList) {
        ProtectedItem protectedItem = new ProtectedItem(entityLocation, drop);
        protectedItem.setOwnerUUID(enemyId);
        protectedItemQueue.add(protectedItem);
    }
    this.pendingProtectionMap.put(entityLocation, protectedItemQueue);
    String entityName = (entity.getCustomName() == null ? entity.getName() : entity.getCustomName());
    long timeLeftMillis = this.protectedItemMap.getExpiration();
    long timeLeftSeconds = TimeUnit.MILLISECONDS.toSeconds(timeLeftMillis);
    String timeLeft = Long.toString(timeLeftSeconds);
    Replacer replacer = message -> message.replace("{time}", timeLeft).replace("{enemy}", entityName);
    sendMessageWithPrefix(enemy, "expansion.loot-protection.enemy-died", replacer, true);
}
Also used : PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) Item(org.bukkit.entity.Item) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) ExpansionListener(com.github.sirblobman.combatlogx.api.expansion.ExpansionListener) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) Player(org.bukkit.entity.Player) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) EventHandler(org.bukkit.event.EventHandler) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) Location(org.bukkit.Location) Replacer(com.github.sirblobman.api.language.Replacer) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Bukkit(org.bukkit.Bukkit) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PlayerPunishEvent(com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent) Entity(org.bukkit.entity.Entity) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Set(java.util.Set) UUID(java.util.UUID) LivingEntity(org.bukkit.entity.LivingEntity) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) LivingEntity(org.bukkit.entity.LivingEntity) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) UUID(java.util.UUID) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 15 with Replacer

use of com.github.sirblobman.api.language.Replacer 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

Replacer (com.github.sirblobman.api.language.Replacer)15 List (java.util.List)14 Player (org.bukkit.entity.Player)14 Collections (java.util.Collections)12 Set (java.util.Set)12 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)10 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)10 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)9 LanguageManager (com.github.sirblobman.api.language.LanguageManager)8 Map (java.util.Map)8 UUID (java.util.UUID)8 CombatLogCommand (com.github.sirblobman.combatlogx.api.command.CombatLogCommand)7 TimeUnit (java.util.concurrent.TimeUnit)7 CommandSender (org.bukkit.command.CommandSender)7 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)6 UntagReason (com.github.sirblobman.combatlogx.api.object.UntagReason)6 Locale (java.util.Locale)6 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5