mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-25 08:51:49 +01:00
Updated storage system.
This commit is contained in:
parent
d88a5f01fa
commit
4406f60ea0
4
pom.xml
4
pom.xml
@ -1,11 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFurnaces</artifactId>
|
||||
<artifactId>EpicFarming</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>maven-version-number</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicFurnaces-${project.version}</finalName>
|
||||
<finalName>EpicFarming-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -18,7 +18,6 @@ import com.songoda.epicfarming.player.PlayerActionManager;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
import com.songoda.epicfarming.storage.types.StorageMysql;
|
||||
import com.songoda.epicfarming.storage.types.StorageYaml;
|
||||
import com.songoda.epicfarming.tasks.EntityTask;
|
||||
import com.songoda.epicfarming.tasks.FarmTask;
|
||||
@ -29,7 +28,6 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -164,19 +162,28 @@ public class EpicFarming extends SongodaPlugin {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
this.setLocale(getConfig().getString("System.Language Mode"), true);
|
||||
this.locale.reloadMessages();
|
||||
this.blacklistHandler.reload();
|
||||
loadLevelManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return Arrays.asList(levelsFile);
|
||||
}
|
||||
|
||||
private void checkStorage() {
|
||||
if (getConfig().getBoolean("Database.Activate Mysql Support")) {
|
||||
this.storage = new StorageMysql(this);
|
||||
} else {
|
||||
this.storage = new StorageYaml(this);
|
||||
}
|
||||
this.storage = new StorageYaml(this);
|
||||
}
|
||||
|
||||
private void loadLevelManager() {
|
||||
if (!levelsFile.getFile().exists())
|
||||
this.saveResource("levels.yml", false);
|
||||
levelsFile.load();
|
||||
|
||||
|
||||
// Load an instance of LevelManager
|
||||
levelManager = new LevelManager();
|
||||
|
||||
@ -206,14 +213,6 @@ public class EpicFarming extends SongodaPlugin {
|
||||
storage.doSave();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
locale.reloadMessages();
|
||||
references = new References();
|
||||
this.hookManager = new HookManager(this);
|
||||
this.setupConfig();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadDataFile() {
|
||||
dataFile.getConfig().options().copyDefaults(true);
|
||||
dataFile.saveConfig();
|
||||
|
@ -1,25 +1,26 @@
|
||||
package com.songoda.epicfarming.storage;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.ConfigWrapper;
|
||||
import com.songoda.epicFarming.EpicFarming;
|
||||
import com.songoda.epicFarming.boost.BoostData;
|
||||
import com.songoda.epicFarming.furnace.Furnace;
|
||||
import com.songoda.epicFarming.utils.Methods;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Storage {
|
||||
|
||||
protected final EpicFarming instance;
|
||||
protected final ConfigWrapper dataFile;
|
||||
protected final EpicFarming plugin;
|
||||
protected final Config dataFile;
|
||||
|
||||
public Storage(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
this.dataFile = new ConfigWrapper(instance, "", "data.yml");
|
||||
this.dataFile.createNewFile(null, "EpicFarming Data File");
|
||||
this.dataFile.getConfig().options().copyDefaults(true);
|
||||
this.dataFile.saveConfig();
|
||||
public Storage(EpicFarming plugin) {
|
||||
this.plugin = plugin;
|
||||
this.dataFile = new Config(plugin, "data.yml");
|
||||
this.dataFile.load();
|
||||
}
|
||||
|
||||
public abstract boolean containsGroup(String group);
|
||||
@ -29,28 +30,28 @@ public abstract class Storage {
|
||||
public abstract void prepareSaveItem(String group, StorageItem... items);
|
||||
|
||||
public void updateData(EpicFarming instance) {
|
||||
/*
|
||||
* Dump FarmManager to file.
|
||||
*/
|
||||
for (Farm farm : instance.getFarmManager().getFarms().values()) {
|
||||
if (farm.getLocation() == null
|
||||
|| farm.getLocation().getWorld() == null) continue;
|
||||
String locstr = Methods.serializeLocation(farm.getLocation());
|
||||
prepareSaveItem("farms",new StorageItem("location",locstr),
|
||||
new StorageItem("level",farm.getLevel().getLevel()),
|
||||
new StorageItem("placedby",farm.getPlacedBy().toString()),
|
||||
new StorageItem("contents",((Farm)farm).dumpInventory()));
|
||||
}
|
||||
/*
|
||||
* Dump FarmManager to file.
|
||||
*/
|
||||
for (Farm farm : instance.getFarmManager().getFarms().values()) {
|
||||
if (farm.getLocation() == null
|
||||
|| farm.getLocation().getWorld() == null) continue;
|
||||
String locstr = Methods.serializeLocation(farm.getLocation());
|
||||
prepareSaveItem("farms",new StorageItem("location",locstr),
|
||||
new StorageItem("level",farm.getLevel().getLevel()),
|
||||
new StorageItem("placedby",farm.getPlacedBy().toString()),
|
||||
new StorageItem("contents",((Farm)farm).dumpInventory()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump BoostManager to file.
|
||||
*/
|
||||
for (BoostData boostData : instance.getBoostManager().getBoosts()) {
|
||||
String endTime = String.valueOf(boostData.getEndTime());
|
||||
prepareSaveItem("boosts",new StorageItem("endtime",endTime),
|
||||
new StorageItem("amount",boostData.getMultiplier()),
|
||||
new StorageItem("player",boostData.getPlayer()));
|
||||
}
|
||||
/*
|
||||
* Dump BoostManager to file.
|
||||
*/
|
||||
for (BoostData boostData : instance.getBoostManager().getBoosts()) {
|
||||
String endTime = String.valueOf(boostData.getEndTime());
|
||||
prepareSaveItem("boosts",new StorageItem("endtime",endTime),
|
||||
new StorageItem("amount",boostData.getMultiplier()),
|
||||
new StorageItem("player",boostData.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void doSave();
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.songoda.epicfarming.storage;
|
||||
|
||||
import com.songoda.epicfarming.utils.Serializers;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.songoda.epicFarming.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageItem {
|
||||
|
||||
private final Object object;
|
||||
private String key = null;
|
||||
|
||||
private Object object;
|
||||
|
||||
public StorageItem(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
@ -21,12 +20,19 @@ public class StorageItem {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public StorageItem(String key, List<ItemStack> material) {
|
||||
if (material == null || material.isEmpty()) return;
|
||||
public StorageItem(String key, List<String> string) {
|
||||
StringBuilder object = new StringBuilder();
|
||||
for (ItemStack m : material) {
|
||||
if (m == null) continue;
|
||||
object.append(Serializers.serialize(m));
|
||||
for (String s : string) {
|
||||
object.append(s).append(";");
|
||||
}
|
||||
this.key = key;
|
||||
this.object = object.toString();
|
||||
}
|
||||
|
||||
public StorageItem(String key, boolean type, List<Location> blocks) {
|
||||
StringBuilder object = new StringBuilder();
|
||||
for (Location location : blocks) {
|
||||
object.append(Methods.serializeLocation(location));
|
||||
object.append(";;");
|
||||
}
|
||||
this.key = key;
|
||||
@ -39,32 +45,36 @@ public class StorageItem {
|
||||
|
||||
public String asString() {
|
||||
if (object == null) return null;
|
||||
return (String)object;
|
||||
return (String) object;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
if (object == null) return false;
|
||||
return (boolean)object;
|
||||
if (object instanceof Integer) return (Integer) object == 1;
|
||||
return (boolean) object;
|
||||
}
|
||||
|
||||
public int asInt() {
|
||||
if (object == null) return 0;
|
||||
return (int)object;
|
||||
return (int) object;
|
||||
}
|
||||
|
||||
public Object asObject() {
|
||||
if (object == null) return null;
|
||||
if (object instanceof Boolean) return (Boolean) object ? 1 : 0;
|
||||
return object;
|
||||
}
|
||||
|
||||
public List<ItemStack> asItemStackList() {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
public List<String> asStringList() {
|
||||
if (object instanceof ArrayList) return new ArrayList<>();
|
||||
List<String> list = new ArrayList<>();
|
||||
if (object == null) return list;
|
||||
String obj = (String) object;
|
||||
if (obj.equals("[]"))return list;
|
||||
List<String> sers = new ArrayList<>(Arrays.asList(obj.split(";;")));
|
||||
for (String ser : sers) {
|
||||
list.add(Serializers.deserialize(ser));
|
||||
String[] stack = ((String) object).split(";");
|
||||
for (String item : stack) {
|
||||
if (item.equals("")) continue;
|
||||
list.add(item);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,195 +0,0 @@
|
||||
package com.songoda.epicfarming.storage.types;
|
||||
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageItem;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.MySQLDatabase;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StorageMysql extends Storage {
|
||||
|
||||
private static Map<String, StorageItem[]> toSave = new HashMap<>();
|
||||
private static Map<String, StorageItem[]> lastSave = new HashMap<>();
|
||||
private MySQLDatabase database;
|
||||
|
||||
public StorageMysql(EpicFarming instance) {
|
||||
super(instance);
|
||||
this.database = new MySQLDatabase(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(String group) {
|
||||
try {
|
||||
DatabaseMetaData dbm = database.getConnection().getMetaData();
|
||||
ResultSet rs = dbm.getTables(null, null, instance.getConfig().getString("Database.Prefix") + group, null);
|
||||
if (rs.next()) {
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageRow> getRowsByGroup(String group) {
|
||||
List<StorageRow> rows = new ArrayList<>();
|
||||
try {
|
||||
ResultSet set = database.getConnection().createStatement().executeQuery(String.format("SELECT * FROM `" + instance.getConfig().getString("Database.Prefix") + "%s`", group));
|
||||
while (set.next()) {
|
||||
Map<String, StorageItem> items = new HashMap<>();
|
||||
|
||||
String key = set.getString(1);
|
||||
for (int i = 2; i <= set.getMetaData().getColumnCount(); i++) {
|
||||
if (set.getObject(i) == null || set.getObject(i) == "") continue;
|
||||
StorageItem item = new StorageItem(set.getObject(i));
|
||||
items.put(set.getMetaData().getColumnName(i), item);
|
||||
}
|
||||
StorageRow row = new StorageRow(key, items);
|
||||
rows.add(row);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSaveItem(String group, StorageItem... items) {
|
||||
toSave.put(group + "]" + items[0].asObject().toString(), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSave() {
|
||||
this.updateData(instance);
|
||||
if (toSave.isEmpty()) return;
|
||||
Map<String, StorageItem[]> nextSave = new HashMap<>(toSave);
|
||||
|
||||
if (lastSave.isEmpty())
|
||||
lastSave.putAll(toSave);
|
||||
|
||||
this.makeBackup();
|
||||
this.save();
|
||||
|
||||
toSave.clear();
|
||||
lastSave.clear();
|
||||
lastSave.putAll(nextSave);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
try {
|
||||
Statement stmt = database.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
last:
|
||||
for (Map.Entry<String, StorageItem[]> last : lastSave.entrySet()) {
|
||||
String lastKey = last.getKey().split("]")[0];
|
||||
String lastValue = last.getValue()[0].asObject().toString();
|
||||
|
||||
for (Map.Entry<String, StorageItem[]> to : toSave.entrySet()) {
|
||||
String toKey = to.getKey().split("]")[0];
|
||||
if (!toKey.equals(lastKey)
|
||||
|| !to.getValue()[0].asObject().equals(lastValue)
|
||||
|| to.getValue().length != last.getValue().length)
|
||||
continue;
|
||||
toSave.remove(toKey);
|
||||
for (int i = 0; i < to.getValue().length - 1; i ++) {
|
||||
if (to.getValue()[i].asObject() != null
|
||||
&& !to.getValue()[i].asObject().toString()
|
||||
.equals(last.getValue()[i].asObject().toString())) {
|
||||
//Update
|
||||
StorageItem[] items = to.getValue();
|
||||
StringBuilder sql = new StringBuilder(String.format("UPDATE `" + instance.getConfig().getString("Database.Prefix") + "%s`", toKey));
|
||||
|
||||
sql.append(" SET");
|
||||
|
||||
for (StorageItem item : items) {
|
||||
if (item == null || item.asObject() == null) continue;
|
||||
String key = item.getKey().split("]")[0];
|
||||
sql.append(String.format("`%s` = '%s', ", key, item.asObject().toString()));
|
||||
}
|
||||
|
||||
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
|
||||
|
||||
sql.append(String.format(" WHERE `%s`='%s'", last.getValue()[0].getKey(), last.getValue()[0].asObject().toString()));
|
||||
|
||||
stmt.addBatch(sql.toString());
|
||||
|
||||
continue last;
|
||||
}
|
||||
}
|
||||
// Already up to date.
|
||||
|
||||
continue last;
|
||||
}
|
||||
//Was not found delete.
|
||||
StringBuilder sql = new StringBuilder(String.format("DELETE FROM `" + instance.getConfig().getString("Database.Prefix") + "%s`", lastKey));
|
||||
sql.append(String.format(" WHERE `%s`='%s'", last.getValue()[0].getKey(), last.getValue()[0].asObject().toString()));
|
||||
stmt.addBatch(sql.toString());
|
||||
|
||||
}
|
||||
|
||||
for (Map.Entry<String, StorageItem[]> to : toSave.entrySet()) {
|
||||
String toKey = to.getKey().split("]")[0];
|
||||
//Add
|
||||
StorageItem[] items = to.getValue();
|
||||
StringBuilder sql = new StringBuilder(String.format("INSERT INTO `" + instance.getConfig().getString("Database.Prefix") + "%s`", toKey));
|
||||
|
||||
sql.append(" (");
|
||||
|
||||
for (StorageItem item : items) {
|
||||
if (item == null || item.asObject() == null) continue;
|
||||
String key = item.getKey().split("]")[0];
|
||||
sql.append(String.format("`%s`, ", key));
|
||||
}
|
||||
|
||||
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
|
||||
|
||||
sql.append(") VALUES (");
|
||||
|
||||
for (StorageItem item : items) {
|
||||
if (item == null || item.asObject() == null) continue;
|
||||
sql.append(String.format("'%s', ", item.asObject().toString()));
|
||||
}
|
||||
|
||||
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
|
||||
|
||||
sql.append(");");
|
||||
|
||||
stmt.addBatch(sql.toString());
|
||||
}
|
||||
|
||||
stmt.executeBatch();
|
||||
|
||||
toSave.clear();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeBackup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
try {
|
||||
database.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfarming.storage.types;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageItem;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
import com.songoda.epicFarming.EpicFarming;
|
||||
import com.songoda.epicFarming.storage.Storage;
|
||||
import com.songoda.epicFarming.storage.StorageItem;
|
||||
import com.songoda.epicFarming.storage.StorageRow;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
|
||||
@ -12,30 +12,30 @@ import java.util.*;
|
||||
|
||||
public class StorageYaml extends Storage {
|
||||
|
||||
private static final Map<String, Object> toSave = new HashMap<>();
|
||||
private static Map<String, Object> lastSave = null;
|
||||
private final Map<String, Object> toSave = new HashMap<>();
|
||||
private Map<String, Object> lastSave = null;
|
||||
|
||||
public StorageYaml(EpicFarming instance) {
|
||||
super(instance);
|
||||
public StorageYaml(EpicFarming plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(String group) {
|
||||
return dataFile.getConfig().contains("data." + group);
|
||||
return dataFile.contains("data." + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageRow> getRowsByGroup(String group) {
|
||||
List<StorageRow> rows = new ArrayList<>();
|
||||
ConfigurationSection currentSection = dataFile.getConfig().getConfigurationSection("data." + group);
|
||||
ConfigurationSection currentSection = dataFile.getConfigurationSection("data." + group);
|
||||
for (String key : currentSection.getKeys(false)) {
|
||||
|
||||
Map<String, StorageItem> items = new HashMap<>();
|
||||
ConfigurationSection currentSection2 = dataFile.getConfig().getConfigurationSection("data." + group + "." + key);
|
||||
ConfigurationSection currentSection2 = dataFile.getConfigurationSection("data." + group + "." + key);
|
||||
for (String key2 : currentSection2.getKeys(false)) {
|
||||
String path = "data." + group + "." + key + "." + key2;
|
||||
items.put(key2, new StorageItem(dataFile.getConfig().get(path) instanceof MemorySection
|
||||
? convertToInLineList(path) : dataFile.getConfig().get(path)));
|
||||
items.put(key2, new StorageItem(dataFile.get(path) instanceof MemorySection
|
||||
? convertToInLineList(path) : dataFile.get(path)));
|
||||
}
|
||||
if (items.isEmpty()) continue;
|
||||
StorageRow row = new StorageRow(key, items);
|
||||
@ -46,8 +46,8 @@ public class StorageYaml extends Storage {
|
||||
|
||||
private String convertToInLineList(String path) {
|
||||
StringBuilder converted = new StringBuilder();
|
||||
for (String key : dataFile.getConfig().getConfigurationSection(path).getKeys(false)) {
|
||||
converted.append(key).append(":").append(dataFile.getConfig().getInt(path + "." + key)).append(";");
|
||||
for (String key : dataFile.getConfigurationSection(path).getKeys(false)) {
|
||||
converted.append(key).append(":").append(dataFile.getInt(path + "." + key)).append(";");
|
||||
}
|
||||
return converted.toString();
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class StorageYaml extends Storage {
|
||||
|
||||
@Override
|
||||
public void doSave() {
|
||||
this.updateData(instance);
|
||||
this.updateData(plugin);
|
||||
|
||||
if (lastSave == null)
|
||||
lastSave = new HashMap<>(toSave);
|
||||
@ -85,19 +85,19 @@ public class StorageYaml extends Storage {
|
||||
if (toSave.containsKey(entry.getKey())) {
|
||||
Object newValue = toSave.get(entry.getKey());
|
||||
if (!entry.getValue().equals(newValue)) {
|
||||
dataFile.getConfig().set(entry.getKey(), newValue);
|
||||
dataFile.set(entry.getKey(), newValue);
|
||||
}
|
||||
toSave.remove(entry.getKey());
|
||||
} else {
|
||||
dataFile.getConfig().set(entry.getKey(), null);
|
||||
dataFile.set(entry.getKey(), null);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Object> entry : toSave.entrySet()) {
|
||||
dataFile.getConfig().set(entry.getKey(), entry.getValue());
|
||||
dataFile.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
dataFile.saveConfig();
|
||||
dataFile.save();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -105,15 +105,15 @@ public class StorageYaml extends Storage {
|
||||
|
||||
@Override
|
||||
public void makeBackup() {
|
||||
File data = new File(instance.getDataFolder(), "data.yml");
|
||||
File dataClone = new File(instance.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml");
|
||||
File data = new File(plugin.getDataFolder(), "data.yml");
|
||||
File dataClone = new File(plugin.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml");
|
||||
try {
|
||||
copyFile(data, dataClone);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Deque<File> backups = new ArrayDeque<>();
|
||||
for (File file : Objects.requireNonNull(instance.getDataFolder().listFiles())) {
|
||||
for (File file : Objects.requireNonNull(plugin.getDataFolder().listFiles())) {
|
||||
if (file.getName().toLowerCase().contains("data-backup")) {
|
||||
backups.add(file);
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class StorageYaml extends Storage {
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
dataFile.saveConfig();
|
||||
dataFile.save();
|
||||
}
|
||||
|
||||
private static void copyFile(File source, File dest) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user