mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-01-18 21:41:27 +01:00
settings refactor
This commit is contained in:
parent
d628eb9f8c
commit
96f4576190
10
pom.xml
10
pom.xml
@ -102,6 +102,16 @@
|
|||||||
<artifactId>jobs</artifactId>
|
<artifactId>jobs</artifactId>
|
||||||
<version>4.10.3</version>
|
<version>4.10.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bgsoftware</groupId>
|
||||||
|
<artifactId>WildStacker</artifactId>
|
||||||
|
<version>2-9-0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>uk.antiperson</groupId>
|
||||||
|
<artifactId>stackmob</artifactId>
|
||||||
|
<version>4-0-2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.minebuilders</groupId>
|
<groupId>me.minebuilders</groupId>
|
||||||
<artifactId>Clearlag</artifactId>
|
<artifactId>Clearlag</artifactId>
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
package com.songoda.ultimatestacker.storage;
|
package com.songoda.ultimatestacker.storage;
|
||||||
|
|
||||||
|
import com.songoda.core.configuration.Config;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.utils.ConfigWrapper;
|
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
|
||||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
|
||||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class Storage {
|
public abstract class Storage {
|
||||||
|
|
||||||
protected final UltimateStacker instance;
|
protected final UltimateStacker instance;
|
||||||
protected final ConfigWrapper dataFile;
|
protected final Config dataFile;
|
||||||
|
|
||||||
public Storage(UltimateStacker instance) {
|
public Storage(UltimateStacker instance) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.dataFile = new ConfigWrapper(instance, "", "data.yml");
|
this.dataFile = new Config(instance, "data.yml");
|
||||||
this.dataFile.createNewFile(null, "UltimateStacker Data File");
|
this.dataFile.setHeader("UltimateStacker Data File");
|
||||||
this.dataFile.getConfig().options().copyDefaults(true);
|
this.dataFile.setAutosave(true).setAutosaveInterval(120);
|
||||||
this.dataFile.saveConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean containsGroup(String group);
|
public abstract boolean containsGroup(String group);
|
||||||
|
@ -14,7 +14,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class StorageMysql extends Storage {
|
public class StorageMysql extends Storage {
|
||||||
|
|
||||||
|
@ -6,9 +6,19 @@ import com.songoda.ultimatestacker.storage.StorageItem;
|
|||||||
import com.songoda.ultimatestacker.storage.StorageRow;
|
import com.songoda.ultimatestacker.storage.StorageRow;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.MemorySection;
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
import java.io.File;
|
||||||
import java.io.*;
|
import java.io.FileInputStream;
|
||||||
import java.util.*;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class StorageYaml extends Storage {
|
public class StorageYaml extends Storage {
|
||||||
|
|
||||||
@ -21,21 +31,21 @@ public class StorageYaml extends Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsGroup(String group) {
|
public boolean containsGroup(String group) {
|
||||||
return dataFile.getConfig().contains("data." + group);
|
return dataFile.contains("data." + group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StorageRow> getRowsByGroup(String group) {
|
public List<StorageRow> getRowsByGroup(String group) {
|
||||||
List<StorageRow> rows = new ArrayList<>();
|
List<StorageRow> rows = new ArrayList<>();
|
||||||
ConfigurationSection currentSection = dataFile.getConfig().getConfigurationSection("data." + group);
|
ConfigurationSection currentSection = dataFile.getConfigurationSection("data." + group);
|
||||||
for (String key : currentSection.getKeys(false)) {
|
for (String key : currentSection.getKeys(false)) {
|
||||||
|
|
||||||
Map<String, StorageItem> items = new HashMap<>();
|
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)) {
|
for (String key2 : currentSection2.getKeys(false)) {
|
||||||
String path = "data." + group + "." + key + "." + key2;
|
String path = "data." + group + "." + key + "." + key2;
|
||||||
items.put(key2, new StorageItem(dataFile.getConfig().get(path) instanceof MemorySection
|
items.put(key2, new StorageItem(dataFile.get(path) instanceof MemorySection
|
||||||
? convertToInLineList(path) : dataFile.getConfig().get(path)));
|
? convertToInLineList(path) : dataFile.get(path)));
|
||||||
}
|
}
|
||||||
if (items.isEmpty()) continue;
|
if (items.isEmpty()) continue;
|
||||||
StorageRow row = new StorageRow(key, items);
|
StorageRow row = new StorageRow(key, items);
|
||||||
@ -46,8 +56,8 @@ public class StorageYaml extends Storage {
|
|||||||
|
|
||||||
private String convertToInLineList(String path) {
|
private String convertToInLineList(String path) {
|
||||||
StringBuilder converted = new StringBuilder();
|
StringBuilder converted = new StringBuilder();
|
||||||
for (String key : dataFile.getConfig().getConfigurationSection(path).getKeys(false)) {
|
for (String key : dataFile.getConfigurationSection(path).getKeys(false)) {
|
||||||
converted.append(key).append(":").append(dataFile.getConfig().getInt(path + "." + key)).append(";");
|
converted.append(key).append(":").append(dataFile.getInt(path + "." + key)).append(";");
|
||||||
}
|
}
|
||||||
return converted.toString();
|
return converted.toString();
|
||||||
}
|
}
|
||||||
@ -85,19 +95,19 @@ public class StorageYaml extends Storage {
|
|||||||
if (toSave.containsKey(entry.getKey())) {
|
if (toSave.containsKey(entry.getKey())) {
|
||||||
Object newValue = toSave.get(entry.getKey());
|
Object newValue = toSave.get(entry.getKey());
|
||||||
if (!entry.getValue().equals(newValue)) {
|
if (!entry.getValue().equals(newValue)) {
|
||||||
dataFile.getConfig().set(entry.getKey(), newValue);
|
dataFile.set(entry.getKey(), newValue);
|
||||||
}
|
}
|
||||||
toSave.remove(entry.getKey());
|
toSave.remove(entry.getKey());
|
||||||
} else {
|
} else {
|
||||||
dataFile.getConfig().set(entry.getKey(), null);
|
dataFile.set(entry.getKey(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, Object> entry : toSave.entrySet()) {
|
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) {
|
} catch (NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -125,10 +135,9 @@ public class StorageYaml extends Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
dataFile.saveConfig();
|
dataFile.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void copyFile(File source, File dest) throws IOException {
|
private static void copyFile(File source, File dest) throws IOException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user