Search in sources :

Example 6 with Replacer

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

the class CommandCombatLogXAbout method execute.

@Override
protected boolean execute(CommandSender sender, String[] args) {
    if (!checkPermission(sender, "combatlogx.command.combatlogx.about", true)) {
        return true;
    }
    if (args.length < 1) {
        return false;
    }
    String expansionName = args[0];
    Optional<Expansion> optionalExpansion = getExpansion(expansionName);
    if (!optionalExpansion.isPresent()) {
        Replacer replacer = message -> message.replace("{target}", expansionName);
        sendMessageWithPrefix(sender, "error.unknown-expansion", replacer, true);
        return true;
    }
    Expansion expansion = optionalExpansion.get();
    sendExpansionInformation(sender, expansion);
    return true;
}
Also used : ExpansionManager(com.github.sirblobman.combatlogx.api.expansion.ExpansionManager) CommandSender(org.bukkit.command.CommandSender) CombatLogCommand(com.github.sirblobman.combatlogx.api.command.CombatLogCommand) Set(java.util.Set) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ArrayList(java.util.ArrayList) MessageUtility(com.github.sirblobman.api.utility.MessageUtility) HashSet(java.util.HashSet) List(java.util.List) State(com.github.sirblobman.combatlogx.api.expansion.Expansion.State) Replacer(com.github.sirblobman.api.language.Replacer) Optional(java.util.Optional) ExpansionDescription(com.github.sirblobman.combatlogx.api.expansion.ExpansionDescription) Collections(java.util.Collections) Replacer(com.github.sirblobman.api.language.Replacer) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion)

Example 7 with Replacer

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

the class ListenerCommands method checkEvent.

private void checkEvent(PlayerCommandPreprocessEvent e) {
    Player player = e.getPlayer();
    if (!isInCombat(player) && !isInCooldown(player))
        return;
    if (hasBypassPermission(player))
        return;
    String command = e.getMessage();
    String realCommand = fixCommand(command);
    if (isAllowed(realCommand) || !isBlocked(realCommand))
        return;
    e.setCancelled(true);
    Replacer replacer = message -> message.replace("{command}", realCommand);
    sendMessageIgnoreCooldown(player, "expansion.cheat-prevention.command-blocked", replacer);
}
Also used : PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) PermissionDefault(org.bukkit.permissions.PermissionDefault) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) HashMap(java.util.HashMap) UUID(java.util.UUID) Player(org.bukkit.entity.Player) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) EventHandler(org.bukkit.event.EventHandler) Permission(org.bukkit.permissions.Permission) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Map(java.util.Map) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Player(org.bukkit.entity.Player) Replacer(com.github.sirblobman.api.language.Replacer)

Example 8 with Replacer

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

Example 9 with Replacer

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

the class CommandCombatLogXToggle method toggleValue.

private void toggleValue(Player player, String value) {
    ICombatLogX plugin = getCombatLogX();
    PlayerDataManager playerDataManager = plugin.getPlayerDataManager();
    LanguageManager languageManager = getLanguageManager();
    YamlConfiguration playerData = playerDataManager.get(player);
    boolean currentValue = playerData.getBoolean(value, true);
    playerData.set(value, !currentValue);
    playerDataManager.save(player);
    boolean status = playerData.getBoolean(value, true);
    String statusPath = ("placeholder.toggle." + (status ? "enabled" : "disabled"));
    String statusString = languageManager.getMessage(player, statusPath, null, true);
    Replacer replacer = message -> message.replace("{status}", statusString);
    String messagePath = ("command.combatlogx.toggle-" + value);
    sendMessageWithPrefix(player, messagePath, replacer, true);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) Replacer(com.github.sirblobman.api.language.Replacer) Locale(java.util.Locale) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) LanguageManager(com.github.sirblobman.api.language.LanguageManager) CombatLogPlayerCommand(com.github.sirblobman.combatlogx.api.command.CombatLogPlayerCommand) Player(org.bukkit.entity.Player) Collections(java.util.Collections) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) LanguageManager(com.github.sirblobman.api.language.LanguageManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager)

Example 10 with Replacer

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

the class CommandCombatLogXUntag method execute.

@Override
protected boolean execute(CommandSender sender, String[] args) {
    if (!checkPermission(sender, "combatlogx.command.combatlogx.untag", 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();
    if (!combatManager.isInCombat(target)) {
        sendMessageWithPrefix(sender, "error.target-not-in-combat", replacer, true);
        return true;
    }
    combatManager.untag(target, UntagReason.EXPIRE);
    sendMessageWithPrefix(sender, "command.combatlogx.untag-player", replacer, true);
    return true;
}
Also used : UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) CommandSender(org.bukkit.command.CommandSender) CombatLogCommand(com.github.sirblobman.combatlogx.api.command.CombatLogCommand) Replacer(com.github.sirblobman.api.language.Replacer) Set(java.util.Set) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) Collections(java.util.Collections) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) Replacer(com.github.sirblobman.api.language.Replacer) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

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