Search in sources :

Example 56 with ICombatLogX

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

the class ExpansionManager method disableExpansions.

public void disableExpansions() {
    ICombatLogX plugin = getPlugin();
    Logger logger = plugin.getLogger();
    logger.info("Disabling expansions...");
    List<Expansion> enabledExpansionList = getEnabledExpansions();
    if (enabledExpansionList.isEmpty()) {
        logger.info("There were no expansions to disable.");
    } else {
        for (Expansion expansion : enabledExpansionList) {
            disableExpansion(expansion);
            logger.info(" ");
        }
    }
    this.expansionMap.clear();
    this.classNameMap.clear();
    this.expansionClassLoaderMap.clear();
    logger.info("Successfully disabled all expansions.");
}
Also used : ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Logger(java.util.logging.Logger)

Example 57 with ICombatLogX

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

the class ExpansionManager method loadExpansion.

private void loadExpansion(File expansionFile) {
    ICombatLogX plugin = getPlugin();
    Logger logger = plugin.getLogger();
    plugin.printDebug("Attempting to load expansion from file '" + expansionFile + "'...");
    Expansion expansion;
    ExpansionClassLoader expansionClassLoader;
    try (JarFile jarFile = new JarFile(expansionFile)) {
        YamlConfiguration description = getExpansionDescription(jarFile);
        Class<? extends ExpansionManager> managerClass = getClass();
        ClassLoader managerClassLoader = managerClass.getClassLoader();
        PluginManager pluginManager = Bukkit.getPluginManager();
        if (description.isList("plugin-depend")) {
            List<String> pluginDependList = description.getStringList("plugin-depend");
            for (String pluginName : pluginDependList) {
                Plugin dependencyPlugin = pluginManager.getPlugin(pluginName);
                if (dependencyPlugin != null)
                    continue;
                logger.warning("Failed to load expansion '" + expansionFile + "' because a plugin " + "dependency was not loaded: " + pluginName);
                return;
            }
        }
        if (description.isList("expansion-depend")) {
            List<String> expansionDependList = description.getStringList("expansion-depend");
            for (String expansionName : expansionDependList) {
                if (this.expansionMap.containsKey(expansionName))
                    continue;
                logger.warning("Failed to load expansion '" + expansionFile + "' because an expansion" + " dependency was missing: " + expansionName);
                return;
            }
        }
        expansionClassLoader = new ExpansionClassLoader(this, description, expansionFile, managerClassLoader);
        expansion = expansionClassLoader.getExpansion();
    } catch (Exception ex) {
        logger.warning("An expansion failed to load because an error occurred.");
        logger.warning("If debug-mode is enabled, the full error will be displayed below.");
        this.plugin.printDebug(ex);
        return;
    }
    File pluginFolder = plugin.getDataFolder();
    File expansionsFolder = new File(pluginFolder, "expansions");
    String expansionName = expansion.getName();
    File dataFolder = new File(expansionsFolder, expansionName);
    if (!dataFolder.exists() && !dataFolder.mkdirs()) {
        logger.warning("Failed to create folder for expansion '" + expansionName + "'.");
        return;
    }
    expansion.setFile(expansionFile);
    expansion.setDataFolder(dataFolder);
    this.expansionMap.put(expansionName, expansion);
    this.expansionClassLoaderMap.put(expansion, expansionClassLoader);
    try {
        ExpansionDescription description = expansion.getDescription();
        String fullName = description.getFullName();
        logger.info("Loading expansion '" + fullName + "'...");
        expansion.onLoad();
        expansion.setState(State.LOADED);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "An error occurred while loading an expansion:", ex);
        logger.warning("Failed to load expansion from file '" + expansionFile + "'.");
    }
}
Also used : Logger(java.util.logging.Logger) JarFile(java.util.jar.JarFile) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) PluginManager(org.bukkit.plugin.PluginManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) JarFile(java.util.jar.JarFile) File(java.io.File) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 58 with ICombatLogX

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

the class CombatLogCommand method getMessageWithPrefix.

protected final String getMessageWithPrefix(@Nullable CommandSender sender, @NotNull String key, @Nullable Replacer replacer, boolean color) {
    ICombatLogX plugin = getCombatLogX();
    LanguageManager languageManager = plugin.getLanguageManager();
    String message = languageManager.getMessage(sender, key, replacer, color);
    if (message.isEmpty())
        return "";
    String prefix = languageManager.getMessage(sender, "prefix", null, true);
    return (prefix.isEmpty() ? message : String.format(Locale.US, "%s %s", prefix, message));
}
Also used : LanguageManager(com.github.sirblobman.api.language.LanguageManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 59 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX 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 60 with ICombatLogX

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

Aggregations

ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)96 ExpansionManager (com.github.sirblobman.combatlogx.api.expansion.ExpansionManager)24 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)19 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)19 Player (org.bukkit.entity.Player)18 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)14 LivingEntity (org.bukkit.entity.LivingEntity)13 LanguageManager (com.github.sirblobman.api.language.LanguageManager)12 Logger (java.util.logging.Logger)11 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)10 MultiVersionHandler (com.github.sirblobman.api.nms.MultiVersionHandler)9 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)8 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)8 List (java.util.List)8 Replacer (com.github.sirblobman.api.language.Replacer)6 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)5 State (com.github.sirblobman.combatlogx.api.expansion.Expansion.State)5 Collections (java.util.Collections)5 EventHandler (org.bukkit.event.EventHandler)5 NewbieHelperExpansion (combatlogx.expansion.newbie.helper.NewbieHelperExpansion)4