0.0.2: YML working !
with no apparent bug !
This commit is contained in:
parent
81a80b79bb
commit
f60f12921e
3 changed files with 48 additions and 20 deletions
|
@ -79,7 +79,7 @@ public class PlayerConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveUsingYml(Player player, Skills skills, String invstr, Integer reverse) throws IOException {
|
public void saveUsingYml(Player player, Skills skills, String invstr, Integer reverse) {
|
||||||
FileConfiguration config = sto.createYml(player);
|
FileConfiguration config = sto.createYml(player);
|
||||||
config.set("name", player.getName());
|
config.set("name", player.getName());
|
||||||
config.set("health", skills.getHealth());
|
config.set("health", skills.getHealth());
|
||||||
|
@ -103,7 +103,11 @@ public class PlayerConfig {
|
||||||
config.set("ec", ecstr);
|
config.set("ec", ecstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.save(main.getDataFolder() + "/" + player.getUniqueId() + "/" + "playerInfo.yml");
|
try {
|
||||||
|
config.save(main.getDataFolder() + "/playerInfo/" + player.getUniqueId() + "/" + "playerInfo.yml");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUsingMongoDB(Player player) {
|
public void loadUsingMongoDB(Player player) {
|
||||||
|
@ -135,7 +139,7 @@ public class PlayerConfig {
|
||||||
profileManager.setPlayerInventory(player.getUniqueId(), invvv);
|
profileManager.setPlayerInventory(player.getUniqueId(), invvv);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUsingYml(Player player) {
|
public void loadUsingYml(Player player) throws IOException {
|
||||||
FileConfiguration config = sto.createYml(player);
|
FileConfiguration config = sto.createYml(player);
|
||||||
Skills skills = new Skills((Integer) config.get("health"), (Integer) config.get("defense"), (Integer) config.get("speed"), (Integer) config.get("strength"));
|
Skills skills = new Skills((Integer) config.get("health"), (Integer) config.get("defense"), (Integer) config.get("speed"), (Integer) config.get("strength"));
|
||||||
Profile profile = new Profile(skills);
|
Profile profile = new Profile(skills);
|
||||||
|
@ -173,25 +177,30 @@ public class PlayerConfig {
|
||||||
String invstr = Utils.listItemStackSerelize(listInv);
|
String invstr = Utils.listItemStackSerelize(listInv);
|
||||||
|
|
||||||
|
|
||||||
switch(sto.getCurrently()) {
|
Object storage = sto.getConfig().get("storage");
|
||||||
case "MONGODB":
|
if ("MONGODB".equals(storage)) {
|
||||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||||
case "MYSQL":
|
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||||
case "YML":
|
} else if ("MYSQL".equals(storage) || "YML".equals(storage)) {
|
||||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
saveUsingYml(player, skills, invstr, reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Player: " + player.getName() + " data successfully saved!");
|
log("Player: " + player.getName() + " data successfully saved!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadPlayerConfig(Player player) {
|
public void loadPlayerConfig(Player player) {
|
||||||
if (StorageManager.getCurrently().equals("MONGODB")) {
|
String st = (String) StorageManager.getConfig().get("storage");
|
||||||
|
if (st.equals("MONGODB")) {
|
||||||
loadUsingMongoDB(player);
|
loadUsingMongoDB(player);
|
||||||
warn("'" + StorageManager.getCurrently()+ "'");
|
warn("'" + st + "'");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
warn("'" + StorageManager.getCurrently()+ "'");
|
warn("'" + st + "'");
|
||||||
loadUsingYml(player);
|
try {
|
||||||
|
loadUsingYml(player);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log("Player: " + player.getName() + " data successfully loaded!");
|
log("Player: " + player.getName() + " data successfully loaded!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class LeaveEvent implements Listener {
|
public class LeaveEvent implements Listener {
|
||||||
|
|
||||||
private final PlayerConfig playerConfig;
|
private final PlayerConfig playerConfig;
|
||||||
|
@ -18,7 +20,7 @@ public class LeaveEvent implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void PlayerLeaveEvent(PlayerQuitEvent e) {
|
public void PlayerLeaveEvent(PlayerQuitEvent e) throws IOException {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
playerConfig.savePlayerConfig(player);
|
playerConfig.savePlayerConfig(player);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,12 @@ import static gq.unurled.raxen.utils.Utils.*;
|
||||||
public class StorageManager {
|
public class StorageManager {
|
||||||
|
|
||||||
private static Raxen main;
|
private static Raxen main;
|
||||||
|
@Getter
|
||||||
private static FileConfiguration config;
|
private static FileConfiguration config;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static MongoDB mongo;
|
private static MongoDB mongo;
|
||||||
@Getter
|
@Getter
|
||||||
private static String currently;
|
|
||||||
@Getter
|
|
||||||
private static Mysql mysql;
|
private static Mysql mysql;
|
||||||
|
|
||||||
public StorageManager(Raxen main) {
|
public StorageManager(Raxen main) {
|
||||||
|
@ -39,17 +38,14 @@ public class StorageManager {
|
||||||
log(s);
|
log(s);
|
||||||
if(s.equalsIgnoreCase("MONGODB")) {
|
if(s.equalsIgnoreCase("MONGODB")) {
|
||||||
mongo.connect();
|
mongo.connect();
|
||||||
currently = "MONGODB";
|
|
||||||
warn("'" + s + "'");
|
warn("'" + s + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(s.equalsIgnoreCase("MYSQL")) {
|
if(s.equalsIgnoreCase("MYSQL")) {
|
||||||
error("Currently not implemented, switching to YML");
|
error("Currently not implemented, switching to YML");
|
||||||
currently = "YML";
|
|
||||||
warn("'" + s + "'");
|
warn("'" + s + "'");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currently = "YML";
|
|
||||||
warn("'" + s + "'");
|
warn("'" + s + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +62,13 @@ public class StorageManager {
|
||||||
|
|
||||||
if (!customFile.exists()) {
|
if (!customFile.exists()) {
|
||||||
customFile.getParentFile().mkdirs();
|
customFile.getParentFile().mkdirs();
|
||||||
main.saveResource(main.getDataFolder() + "/playerInfo/" + player.getUniqueId() + "/playerInfo.yml", false);
|
try {
|
||||||
|
customFile.createNewFile();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
error("Error in Storage Manager saving new File.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customConfig = new YamlConfiguration();
|
customConfig = new YamlConfiguration();
|
||||||
|
@ -75,6 +77,21 @@ public class StorageManager {
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if (customConfig.get("uuid") == null) {
|
||||||
|
customConfig.set("uuid", player.getUniqueId().toString());
|
||||||
|
customConfig.set("name", player.getName());
|
||||||
|
customConfig.set("health", 100);
|
||||||
|
customConfig.set("defense", 50);
|
||||||
|
customConfig.set("speed", 100);
|
||||||
|
customConfig.set("strength", 100);
|
||||||
|
customConfig.set("inv","");
|
||||||
|
customConfig.set("ec","");
|
||||||
|
try {
|
||||||
|
customConfig.save(customFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
return customConfig;
|
return customConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue