Skip to content

Commit

Permalink
Added sftp/ftp schematic files synchronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTuxn committed Sep 21, 2021
1 parent 31ceb68 commit 8d04ec3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/alpsbte/plotsystem/PlotSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void onEnable() {
});

PlotManager.checkPlotsForLastActivity();
PlotManager.syncPlotSchematicFiles();

pluginEnabled = true;
Bukkit.getConsoleSender().sendMessage("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public abstract class ConfigPaths {
public static final String ENABLE_SCORE_REQUIREMENT = "enable-score-requirement";
public static final String DEV_MODE = "dev-mode";

private static final String SYNC_FTP_FILES = "sync-ftp-files.";
public static final String SYNC_FTP_FILES_ENABLED = SYNC_FTP_FILES + "enabled";
public static final String SYNC_FTP_FILES_INTERVAL = SYNC_FTP_FILES + "sync-interval";


// Database
private static final String DATABASE = "database.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package com.alpsbte.plotsystem.core.system.plot;

import com.alpsbte.plotsystem.core.config.ConfigPaths;
import com.alpsbte.plotsystem.core.system.CityProject;
import com.alpsbte.plotsystem.core.system.Country;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
Expand All @@ -44,6 +46,7 @@
import com.alpsbte.plotsystem.utils.ftp.FTPManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -270,7 +273,7 @@ public static CompletableFuture<double[]> convertTerraToPlotXZ(Plot plot, double
}

public static void checkPlotsForLastActivity() {
Bukkit.getScheduler().scheduleAsyncRepeatingTask(PlotSystem.getPlugin(), () -> {
Bukkit.getScheduler().runTaskTimerAsynchronously(PlotSystem.getPlugin(), () -> {
try {
List<Plot> plots = getPlots(Status.unfinished);
long millisIn14Days = 14L * 24 * 60 * 60 * 1000; // Remove all plots which have no activity for the last 14 days
Expand All @@ -293,6 +296,26 @@ public static void checkPlotsForLastActivity() {
}, 0L, 20 * 60 * 60); // Check every hour
}

public static void syncPlotSchematicFiles() {
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
if (config.getBoolean(ConfigPaths.SYNC_FTP_FILES_ENABLED)) {
long interval = config.getLong(ConfigPaths.SYNC_FTP_FILES_INTERVAL);

Bukkit.getScheduler().runTaskTimerAsynchronously(PlotSystem.getPlugin(), () -> {
CityProject.getCityProjects(false).forEach(c -> {
try {
if (c.getCountry().getServer().getFTPConfiguration() != null) {
List<Plot> plots = PlotManager.getPlots(c.getID(), Status.unclaimed);
plots.forEach(Plot::getOutlinesSchematic);
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.INFO, "A SQL error occurred!", ex);
}
});
}, 0L, 20 * interval);
}
}

public static Plot getPlotByWorld(World plotWorld) throws SQLException {
return new Plot(Integer.parseInt(plotWorld.getName().substring(2)));
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/defaultConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ enable-score-requirement: true
# NOTE: Do not change if you do not know what you are doing
dev-mode: false

# Automatic synchronisation of schematic files from SFTP/FTP servers
# [interval] -> default: 3600 seconds (1 hour)
sync-ftp-files:
enabled: true
sync-interval: 3600


# -----------------------------------------------------
# | Supported database: MariaDB
Expand Down Expand Up @@ -80,4 +86,4 @@ error-colour: §c


# NOTE: Do not change
config-version: 1.1
config-version: 1.2

0 comments on commit 8d04ec3

Please sign in to comment.