diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportScheduler.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportScheduler.java index feee1c223..4aaaf2a0b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportScheduler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportScheduler.java @@ -17,7 +17,6 @@ package com.djrapitops.plan.delivery.export; import com.djrapitops.plan.TaskSystem; -import com.djrapitops.plan.delivery.upkeep.ExportTask; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.ExportSettings; @@ -68,9 +67,17 @@ public class ExportScheduler { public void scheduleExport() { scheduleServerPageExport(); + schedulePlayersPageExport(); } - public void scheduleServerPageExport() { + private void schedulePlayersPageExport() { + long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS); + taskSystem.registerTask("Players page export", + new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler) + ).runTaskTimerAsynchronously(0L, period); + } + + private void scheduleServerPageExport() { if (!config.get(ExportSettings.SERVER_PAGE)) return; Collection servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection()); @@ -81,15 +88,11 @@ public class ExportScheduler { long offset = period / serverCount; Optional proxy = servers.stream().filter(Server::isProxy).findFirst(); - proxy.ifPresent(server -> taskSystem.registerTask("Server export", - new ExportTask(exporter, exporter -> exporter.exportServerPage(server), logger, errorHandler)) + proxy.ifPresent(mainServer -> taskSystem.registerTask("Network export", + new ExportTask(exporter, exporter -> exporter.exportServerPage(mainServer), logger, errorHandler)) .runTaskTimerAsynchronously(0L, period) ); - taskSystem.registerTask("Players page export", - new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler) - ).runTaskTimerAsynchronously(0L, period); - int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network. for (Server server : servers) { taskSystem.registerTask("Server export", diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/upkeep/ExportTask.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportTask.java similarity index 95% rename from Plan/common/src/main/java/com/djrapitops/plan/delivery/upkeep/ExportTask.java rename to Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportTask.java index b1ec42cbb..d27c05ee1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/upkeep/ExportTask.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportTask.java @@ -14,9 +14,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with Plan. If not, see . */ -package com.djrapitops.plan.delivery.upkeep; +package com.djrapitops.plan.delivery.export; -import com.djrapitops.plan.delivery.export.Exporter; import com.djrapitops.plan.exceptions.ExportException; import com.djrapitops.plan.utilities.java.ThrowingConsumer; import com.djrapitops.plugin.logging.L; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java index 1497819ef..851e234df 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java @@ -107,7 +107,7 @@ public class Exporter { return true; } catch (IOException | NotFoundException | ParseException e) { failedServers.add(serverUUID); - throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.getMessage(), e); + throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e); } } @@ -127,7 +127,7 @@ public class Exporter { playerPageExporter.export(toDirectory, playerUUID, playerName); return true; } catch (IOException | NotFoundException | ParseException e) { - throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e); + throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e); } } @@ -139,7 +139,7 @@ public class Exporter { playersPageExporter.export(toDirectory); return true; } catch (IOException | NotFoundException | ParseException e) { - throw new ExportException("Failed to export players page, " + e.getMessage(), e); + throw new ExportException("Failed to export players page, " + e.toString(), e); } } @@ -159,7 +159,7 @@ public class Exporter { playerJSONExporter.export(toDirectory, playerUUID, playerName); return true; } catch (IOException e) { - throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e); + throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e); } } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/FileExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/FileExporter.java index f4aee8d74..53c9c4ad7 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/FileExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/FileExporter.java @@ -59,11 +59,10 @@ abstract class FileExporter { void export(Path to, Resource resource) throws IOException { Files.createDirectories(to.getParent()); - if (Files.exists(to)) Files.delete(to); - Files.createFile(to); + try ( InputStream in = resource.asInputStream(); - OutputStream out = Files.newOutputStream(to) + OutputStream out = Files.newOutputStream(to, StandardOpenOption.CREATE) ) { copy(in, out); }