private void checkIfDefaultIP() throws EnableException { String ip = serverProperties.getIp(); if ("0.0.0.0".equals(ip)) { logger.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server."); logger.info("Player Analytics partially enabled (Use /planbungee to reload config)"); throw new EnableException("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server."); } }
@Override public void run() { Statement statement = null; ResultSet resultSet = null; try { if (connection != null && !connection.isClosed()) { statement = connection.createStatement(); resultSet = statement.executeQuery("/* ping */ SELECT 1"); } } catch (SQLException e) { logger.debug("Something went wrong during SQL Connection upkeep task."); try { connection = iReconnect.reconnect(); } catch (SQLException e1) { errorHandler.log(L.ERROR, this.getClass(), e1); logger.error("SQL connection maintaining task had to be closed due to exception."); this.cancel(); } } finally { MiscUtils.close(statement, resultSet); } }
@Override public void runLocally(InfoRequest infoRequest) throws WebException { if (infoRequest instanceof SetupRequest) { throw new NoServersException("Set-up requests can not be run locally."); } logger.getDebugLogger().logOn(DebugChannels.INFO_REQUESTS, "Local: " + infoRequest.getClass().getSimpleName()); infoRequest.runLocally(); } }
private Connection getConnectionFor(String dbFilePath) throws SQLException { try { return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath + "?journal_mode=WAL"); } catch (SQLException ignored) { logger.info(locale.getString(PluginLang.DB_NOTIFY_SQLITE_WAL)); return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath); } }
logger.debug("Verbose debug messages are enabled."); String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")"; logger.info(locale.getString(PluginLang.ENABLED) + benchTime); } catch (AbstractMethodError e) { logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); } catch (EnableException e) { logger.error("----------------------------------------"); logger.error("Error: " + e.getMessage()); logger.error("----------------------------------------"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); onDisable(); } catch (Exception e) { Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); onDisable();
@Override public void enable() { try { bridge.hook(this); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); logger.error("Plan Plugin Bridge not included in the plugin jar."); } }
@Override public void enable() { if (config.isFalse(PluginSettings.CHECK_FOR_UPDATES)) { return; } try { List<VersionInfo> versions = VersionInfoLoader.load(); if (config.isFalse(PluginSettings.NOTIFY_ABOUT_DEV_RELEASES)) { versions = versions.stream().filter(VersionInfo::isRelease).collect(Collectors.toList()); } VersionInfo newestVersion = versions.get(0); if (Version.isNewVersionAvailable(new Version(currentVersion), newestVersion.getVersion())) { newVersionAvailable = newestVersion; String notification = locale.getString( PluginLang.VERSION_AVAILABLE, newestVersion.getVersion().toString(), newestVersion.getChangeLogUrl() ) + (newestVersion.isRelease() ? "" : locale.getString(PluginLang.VERSION_AVAILABLE_DEV)); logger.log(L.INFO_COLOR, "§a----------------------------------------"); logger.log(L.INFO_COLOR, "§a" + notification); logger.log(L.INFO_COLOR, "§a----------------------------------------"); } else { logger.info(locale.getString(PluginLang.VERSION_NEWEST)); } } catch (IOException e) { logger.error(locale.getString(PluginLang.VERSION_FAIL_READ_VERSIONS)); } }
usingHttps = startHttpsServer(); logger.debug(usingHttps ? "Https Start Successful." : "Https Start Failed."); logger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.WEB_SERVER_NOTIFY_HTTP_USER_AUTH)); server = HttpServer.create(new InetSocketAddress(config.get(WebserverSettings.INTERNAL_IP), port), 10); } else if (server == null) { logger.log(L.INFO_COLOR, "§eWebServer: Proxy HTTPS Override enabled. HTTP Server in use, make sure that your Proxy webserver is routing with HTTPS and AlternativeIP.Link points to the Proxy"); server = HttpServer.create(new InetSocketAddress(config.get(WebserverSettings.INTERNAL_IP), port), 10); logger.info(locale.getString(PluginLang.ENABLED_WEB_SERVER, server.getAddress().getPort(), getAccessAddress())); } catch (IllegalArgumentException | IllegalStateException | IOException e) { errorHandler.log(L.ERROR, this.getClass(), e);
public Connection getNewConnection(File dbFile) throws SQLException { String dbFilePath = dbFile.getAbsolutePath(); Connection newConnection = getConnectionFor(dbFilePath); logger.debug("H2 " + dbName + ": Opened a new Connection"); newConnection.setAutoCommit(false); return newConnection; }
@Override public void enable() throws EnableException { geolocationDB = files.getFileFromPluginFolder("GeoIP.dat"); if (config.isTrue(DataGatheringSettings.GEOLOCATIONS)) { try { checkDB(); } catch (UnknownHostException e) { logger.error(locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED)); } catch (IOException e) { throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e); } } else { logger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED)); } }
@Override public void enable() { super.enable(); refreshServerMap(); boolean usingBungeeWebServer = isServerAvailable(); boolean usingAlternativeIP = config.isTrue(WebserverSettings.SHOW_ALTERNATIVE_IP); if (!usingAlternativeIP && serverInfo.getServerProperties().getIp().isEmpty()) { pluginLogger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.ENABLE_NOTIFY_EMPTY_IP)); } if (usingBungeeWebServer && usingAlternativeIP) { String webServerAddress = webServer.get().getAccessAddress(); pluginLogger.info(locale.getString(PluginLang.ENABLE_NOTIFY_ADDRESS_CONFIRMATION, webServerAddress)); } } }
@Override public void enable() throws EnableException { this.port = config.get(WebserverSettings.PORT); initServer(); if (!isEnabled()) { if (Check.isBungeeAvailable() || Check.isVelocityAvailable()) { throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_NO_WEB_SERVER_BUNGEE)); } if (config.isTrue(WebserverSettings.DISABLED)) { logger.warn(locale.getString(PluginLang.ENABLE_NOTIFY_WEB_SERVER_DISABLED)); } else { logger.error(locale.getString(PluginLang.WEB_SERVER_FAIL_PORT_BIND, port)); } } requestHandler.getResponseHandler().registerPages(); }
} catch (Exception e) { if (inDevMode) { logger.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:"); errorHandler.log(L.WARN, this.getClass(), e); exchange.close(); if (inDevMode) { logger.getDebugLogger().logOn( DebugChannels.WEB_REQUESTS, timings.end(requestString).map(Benchmark::toString).orElse("-") + " Code: " + responseCode
private Optional<Locale> loadFromFile(File localeFile) { try { return Optional.of(Locale.fromFile(localeFile)); } catch (IOException e) { logger.warn("Failed to read locale file at " + localeFile.getAbsolutePath() + ", " + e.toString()); logger.warn("Using Default Locale as a fallback (EN)"); } return Optional.empty(); }
public static List<String> lines(PlanPlugin plugin, String resource) throws IOException { List<String> lines = new ArrayList<>(); Scanner scanner = null; try (InputStream inputStream = plugin.getResource(resource)) { scanner = new Scanner(inputStream, "UTF-8"); while (scanner.hasNextLine()) { lines.add(scanner.nextLine()); } } catch (NullPointerException e) { plugin.getPluginLogger().log(L.INFO_COLOR, "§ea Resource was not found inside the jar (" + resource + "), Plan does not support /reload or updates using " + "Plugin Managers, restart the server and see if the error persists."); throw new FileNotFoundException("File not found inside jar: " + resource); } finally { MiscUtils.close(scanner); } return lines; }
private boolean applyPatches() { boolean didApply = false; for (Patch patch : patches) { if (!patch.hasBeenApplied()) { String patchName = patch.getClass().getSimpleName(); logger.info(locale.getString(PluginLang.DB_APPLY_PATCH, patchName)); patch.apply(); didApply = true; } } return didApply; }
private void shutdown() { server.stop(0); Executor executor = server.getExecutor(); if (executor instanceof ExecutorService) { ExecutorService service = (ExecutorService) executor; service.shutdown(); try { if (!service.awaitTermination(5, TimeUnit.SECONDS)) { service.shutdownNow(); } } catch (InterruptedException e) { logger.error("WebServer ExecutorService shutdown thread interrupted on disable: " + e.getMessage()); Thread.currentThread().interrupt(); } } }
logger.error("WebServer: Could not find Keystore: " + e.getMessage()); errorHandler.log(L.ERROR, this.getClass(), e); logger.info("Certificate: " + cert.getType()); startSuccessful = true; } catch (IllegalStateException e) { logger.error(e.getMessage()); errorHandler.log(L.ERROR, this.getClass(), e); } catch (KeyManagementException | NoSuchAlgorithmException e) { logger.error(locale.getString(PluginLang.WEB_SERVER_FAIL_SSL_CONTEXT)); errorHandler.log(L.ERROR, this.getClass(), e); } catch (FileNotFoundException e) { logger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.WEB_SERVER_NOTIFY_NO_CERT_FILE, keyStorePath)); logger.info(locale.getString(PluginLang.WEB_SERVER_NOTIFY_HTTP)); } catch (IOException e) { logger.error("WebServer: " + e); errorHandler.log(L.ERROR, this.getClass(), e); } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) { logger.error(locale.getString(PluginLang.WEB_SERVER_FAIL_STORE_LOAD)); errorHandler.log(L.ERROR, this.getClass(), e);
@Override public void addNewTPSEntry(long nanoTime, long now) { long diff = nanoTime - lastCheckNano; lastCheckNano = nanoTime; if (diff > nanoTime) { // First run's diff = nanoTime + 1, no calc possible. logger.debug("First run of TPSCountTimer Task."); return; } history.add(calculateTPS(now)); }
private void cleanFolder() { long now = System.currentTimeMillis(); for (File file : Objects.requireNonNull(folder.listFiles())) { long forDaysMs = TimeUnit.DAYS.toMillis(config.get(PluginSettings.KEEP_LOGS_DAYS)); if (now - file.lastModified() > (forDaysMs > 0 ? forDaysMs : TimeUnit.DAYS.toMillis(1L))) { try { Files.delete(file.toPath()); } catch (IOException e) { logger.warn("Could not delete log file at: " + file.getAbsolutePath() + ", " + e.getMessage()); } } } } }