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.");
}
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 + "'.");
}
}
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));
}
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;
}
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);
}
Aggregations