Skip to content

Commit

Permalink
+ auto save
Browse files Browse the repository at this point in the history
  • Loading branch information
tim03we committed Mar 25, 2021
1 parent f05aa83 commit 9720899
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tim03we.futureplots</groupId>
<artifactId>FuturePlots</artifactId>
<version>1.4.4-SNAPSHOT</version>
<version>1.4.5-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>tim03we.futureplots</groupId>
<artifactId>FuturePlots</artifactId>
<version>1.4.4-SNAPSHOT</version>
<version>1.4.5-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/tim03we/futureplots/FuturePlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.Entity;
import cn.nukkit.level.Level;
import cn.nukkit.level.Position;
Expand Down Expand Up @@ -97,7 +98,7 @@ private void checkVersion() {
Language.init();
}
}
if(!getConfig().getString("version").equals("1.2.1")) {
if(!getConfig().getString("version").equals("1.2.2")) {
new File(getDataFolder() + "/config_old.yml").delete();
if(new File(getDataFolder() + "/config.yml").renameTo(new File(getDataFolder() + "/config_old.yml"))) {
getLogger().critical("The version of the configuration does not match. You will find the old file marked \"config_old.yml\" in the same directory.");
Expand All @@ -120,7 +121,11 @@ public void onDisable() {

private void initProvider() {
Class<?> providerClass = this.providerClass.get(this.getConfig().getString("provider"));
if (providerClass == null) { this.getLogger().critical("The specified provider could not be found."); }
if (providerClass == null) {
this.getLogger().critical("The specified provider could not be found.");
Server.getInstance().getPluginManager().disablePlugin(Server.getInstance().getPluginManager().getPlugin("FuturePlots"));
return;
}
try { provider = (DataProvider) providerClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) { this.getLogger().critical("The specified provider could not be found.");
getServer().getPluginManager().disablePlugin(getServer().getPluginManager().getPlugin("FuturePlots"));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/tim03we/futureplots/provider/YamlProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cn.nukkit.utils.Config;
import tim03we.futureplots.FuturePlots;
import tim03we.futureplots.utils.Plot;
import tim03we.futureplots.utils.Settings;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,6 +32,15 @@ public class YamlProvider implements DataProvider {

@Override
public void connect() {
if(Settings.use_auto_save) {
runAutoSaveTask();
}
}

private void runAutoSaveTask() {
Server.getInstance().getScheduler().scheduleRepeatingTask(FuturePlots.getInstance(), () -> {
yaml.save();
}, (Settings.auto_save_interval * 20), true);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tim03we/futureplots/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Settings {
public static boolean economy;
public static boolean claim_tp;

public static boolean use_auto_save;
public static int auto_save_interval;

public static void init() {
Config config = FuturePlots.getInstance().getConfig();
File folder = new File(FuturePlots.getInstance().getDataFolder() + "/worlds/");
Expand Down Expand Up @@ -77,6 +80,8 @@ public static void init() {
delete_price = config.getInt("default-settings.price.delete");
dispose_price = config.getInt("default-settings.price.dispose");
erode_price = config.getInt("default-settings.price.erode");
use_auto_save = config.getBoolean("auto-save.use");
auto_save_interval = config.getInt("auto-save.interval");
}

}
9 changes: 8 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Do not change the version, this can lead to deletion of the file
version: "1.2.1"
version: "1.2.2"

# Available languages:
# eng (English), deu (German), kor (Korean), chs (Chinese)
Expand All @@ -9,6 +9,13 @@ lang: "eng"
# Available providers: yaml, mysql, sqlite
provider: "yaml"

# Automatic saving of all plots
# Supported providers: yaml
auto-save:
use: true
# In seconds
interval: 180

# NOT COMPLETED!
# Should the UUID be used to keep the plot when changing the player name
uuid: false
Expand Down
Binary file removed target/FuturePlots-1.4.4-SNAPSHOT-shaded.jar
Binary file not shown.
Binary file removed target/FuturePlots-1.4.4-SNAPSHOT.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Mon Oct 12 22:14:50 CEST 2020
version=1.4.4-SNAPSHOT
#Thu Mar 25 19:11:28 CET 2021
version=1.4.5-SNAPSHOT
groupId=tim03we.futureplots
artifactId=FuturePlots
Binary file removed target/original-FuturePlots-1.4.4-SNAPSHOT.jar
Binary file not shown.

0 comments on commit 9720899

Please sign in to comment.