private boolean deleteConfig() { return config.getFile().delete(); }
public ProtocolConfig(Plugin plugin) { this.plugin = plugin; reloadConfig(); }
/** * Retrieve whether or not the background compiler for structure modifiers is enabled or not. * * @return TRUE if it is enabled, FALSE otherwise. */ public boolean isBackgroundCompilerEnabled() { return getGlobalValue(BACKGROUND_COMPILER_ENABLED, true); }
private void checkUpdates() { // Ignore milliseconds - it's pointless long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND; try { long updateTime = config.getAutoLastTime() + config.getAutoDelay(); // Should we update? if (currentTime > updateTime && !updater.isChecking()) { // Initiate the update as if it came from the console if (config.isAutoDownload()) commandProtocol.updateVersion(getServer().getConsoleSender(), false); else if (config.isAutoNotify()) commandProtocol.checkVersion(getServer().getConsoleSender(), false); else commandProtocol.updateFinished(); } } catch (Exception e) { reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e)); UPDATES_DISABLED = true; } }
config = new ProtocolConfig(this); } catch (Exception e) { reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_LOAD_CONFIG).error(e)); config = new ProtocolConfig(this); } else { reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_DELETE_CONFIG)); if (config.isDebug()) { logger.warning("Debug mode is enabled!"); if (config.isDetailedErrorReporting()) { detailedReporter.setDetailedReporting(true); logger.warning("Detailed error reporting enabled!"); PlayerInjectHooks hook = config.getInjectionMethod();
/** * Store the given time stamp. * * @param value - time stamp to store. */ private void saveLastUpdate(long value) { File dataFile = getLastUpdateFile(); // The data folder must exist dataFile.getParentFile().mkdirs(); if (dataFile.exists()) dataFile.delete(); try { Files.write(Long.toString(value), dataFile, Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Cannot write " + dataFile, e); } }
/** * Retrieve the injection method that has been set in the configuration, or use a default value. * * @return Injection method to use. * @throws IllegalArgumentException If the configuration option is malformed. */ public PlayerInjectHooks getInjectionMethod() throws IllegalArgumentException { String text = global.getString(INJECTION_METHOD); // Default hook if nothing has been set PlayerInjectHooks hook = getDefaultMethod(); if (text != null) hook = PlayerInjectHooks.valueOf(text.toUpperCase(Locale.ENGLISH).replace(" ", "_")); return hook; }
private MinecraftVersion verifyMinecraftVersion() { MinecraftVersion minimum = new MinecraftVersion(ProtocolLibrary.MINIMUM_MINECRAFT_VERSION); MinecraftVersion maximum = new MinecraftVersion(ProtocolLibrary.MAXIMUM_MINECRAFT_VERSION); try { MinecraftVersion current = new MinecraftVersion(getServer()); // Skip certain versions if (!config.getIgnoreVersionCheck().equals(current.getVersion())) { // We'll just warn the user for now if (current.compareTo(minimum) < 0) logger.warning("Version " + current + " is lower than the minimum " + minimum); if (current.compareTo(maximum) > 0) logger.warning("Version " + current + " has not yet been tested! Proceed with caution."); } return current; } catch (Exception e) { reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_PARSE_MINECRAFT_VERSION).error(e).messageParam(maximum)); // Unknown version - just assume it is the latest return maximum; } }
/** * Load the last update time stamp from the file system. * * @return Last update time stamp. */ private long loadLastUpdate() { File dataFile = getLastUpdateFile(); if (dataFile.exists()) { try { return Long.parseLong(Files.toString(dataFile, Charsets.UTF_8)); } catch (NumberFormatException e) { plugin.getLogger().warning("Cannot parse " + dataFile + " as a number."); } catch (IOException e) { plugin.getLogger().warning("Cannot read " + dataFile); } } // Default last update return 0; }
@Override public void reloadConfig() { super.reloadConfig(); // Reload configuration if (config != null) { config.reloadConfig(); } }
/** * Load data sections. * * @param copyDefaults - whether or not to copy configuration defaults. */ private void loadSections(boolean copyDefaults) { if (config != null) { global = config.getConfigurationSection(SECTION_GLOBAL); } if (global != null) { updater = global.getConfigurationSection(SECTION_AUTOUPDATER); if (updater.getValues(true).isEmpty()) { plugin.getLogger().warning("Updater section is missing, regenerate your config!"); } } // Automatically copy defaults if (copyDefaults && (!getFile().exists() || global == null || updater == null)) { loadingSections = true; if (config != null) config.options().copyDefaults(true); plugin.saveDefaultConfig(); plugin.reloadConfig(); loadingSections = false; // Inform the user plugin.getLogger().info("Created default configuration."); } }
/** * Retrieve the unique name of the script engine to use for filtering. * * @return Script engine to use. */ public String getScriptEngineName() { return getGlobalValue(SCRIPT_ENGINE_NAME, "JavaScript"); }
/** * Determine if detailed error reporting is enabled. Default FALSE. * * @return TRUE if it is enabled, FALSE otherwise. */ public boolean isDetailedErrorReporting() { return getGlobalValue(DETAILED_ERROR, false); }
/** * Determine whether or not debug mode is enabled. * <p> * This grants access to the filter command. * * @return TRUE if it is, FALSE otherwise. */ public boolean isDebug() { return getGlobalValue(DEBUG_MODE_ENABLED, false); }
/** * Retrieve whether or not metrics is enabled. * * @return TRUE if metrics is enabled, FALSE otherwise. */ public boolean isMetricsEnabled() { return getGlobalValue(METRICS_ENABLED, true); }
/** * The version of Minecraft to ignore the built-in safety feature. * * @return The version to ignore ProtocolLib's satefy. */ public String getIgnoreVersionCheck() { return getGlobalValue(IGNORE_VERSION_CHECK, ""); }
/** * Retrieve an immutable list of every suppressed report type. * * @return Every suppressed report type. */ public ImmutableList<String> getSuppressedReports() { return ImmutableList.copyOf(getGlobalValue(SUPPRESSED_REPORTS, new ArrayList<String>())); }