mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-02 06:28:52 +00:00
Refactoring into root
AlathraWar2 is unrequired
This commit is contained in:
1 parent
a43b794d1c
commit
110f8d7791
28 files changed
+377
-382
No files matched your search
@@ -0,0 +1,78 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RolesData {
|
||||
|
||||
public String editData(UUID pID, String key, Object value) {
|
||||
Map <String, Object> userData = getPlayer(pID);
|
||||
userData.put(key, value);
|
||||
setPlayer(pID, userData);
|
||||
return "Banana";
|
||||
}
|
||||
|
||||
public Object getData(UUID pID) {
|
||||
return getPlayer(pID);
|
||||
}
|
||||
|
||||
private File getFile(String strID) {
|
||||
// Gets user file, or creates if not yet made.
|
||||
File userFile = new File("plugins" + File.separator + "AlathraWar" + File.separator + "userdata" + File.separator + strID + ".yml");
|
||||
if (!userFile.exists()) {
|
||||
try {
|
||||
userFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating user file for " + strID);
|
||||
}
|
||||
}
|
||||
return userFile;
|
||||
}
|
||||
|
||||
private Map getPlayer(UUID pID) {
|
||||
Map<String, Object> DefaultData = new HashMap<String,Object>();
|
||||
DefaultData.put("MercPermission", false);
|
||||
DefaultData.put("AssassinPermission", false);
|
||||
DefaultData.put("Contracts", new HashMap<String, Map>());
|
||||
|
||||
|
||||
String strID = pID.toString();
|
||||
File userFile = getFile(strID);
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(userFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating FileInputStream for " + strID);
|
||||
}
|
||||
Yaml yaml = new Yaml();
|
||||
Map<String, Object> data = yaml.load(inputStream);
|
||||
//System.out.println(data);
|
||||
if (data == null) {data = DefaultData; setPlayer(pID, data);}
|
||||
return data;
|
||||
}
|
||||
|
||||
private void setPlayer(UUID pID, Map<String, Object> data) {
|
||||
String strID = pID.toString();
|
||||
File userFile = getFile(strID);
|
||||
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = new PrintWriter(userFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating PrintWriter for " + strID);
|
||||
}
|
||||
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setIndent(2);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Yaml yaml = new Yaml(options);
|
||||
yaml.dump(data, writer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import java.io.Reader;
|
||||
import java.io.InputStreamReader;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class SiegeData
|
||||
{
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public SiegeData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "sieges.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("sieges.yml");
|
||||
if (defaultStream != null) {
|
||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "sieges.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("sieges.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import java.io.Reader;
|
||||
import java.io.InputStreamReader;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class WarData
|
||||
{
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public WarData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "wars.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("wars.yml");
|
||||
if (defaultStream != null) {
|
||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "wars.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("wars.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user