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);
|
||||
config.set("name", player.getName());
|
||||
config.set("health", skills.getHealth());
|
||||
|
@ -103,7 +103,11 @@ public class PlayerConfig {
|
|||
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) {
|
||||
|
@ -135,7 +139,7 @@ public class PlayerConfig {
|
|||
profileManager.setPlayerInventory(player.getUniqueId(), invvv);
|
||||
}
|
||||
|
||||
public void loadUsingYml(Player player) {
|
||||
public void loadUsingYml(Player player) throws IOException {
|
||||
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"));
|
||||
Profile profile = new Profile(skills);
|
||||
|
@ -173,25 +177,30 @@ public class PlayerConfig {
|
|||
String invstr = Utils.listItemStackSerelize(listInv);
|
||||
|
||||
|
||||
switch(sto.getCurrently()) {
|
||||
case "MONGODB":
|
||||
Object storage = sto.getConfig().get("storage");
|
||||
if ("MONGODB".equals(storage)) {
|
||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||
case "MYSQL":
|
||||
case "YML":
|
||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||
} else if ("MYSQL".equals(storage) || "YML".equals(storage)) {
|
||||
saveUsingYml(player, skills, invstr, reverse);
|
||||
}
|
||||
|
||||
log("Player: " + player.getName() + " data successfully saved!");
|
||||
}
|
||||
|
||||
public void loadPlayerConfig(Player player) {
|
||||
if (StorageManager.getCurrently().equals("MONGODB")) {
|
||||
String st = (String) StorageManager.getConfig().get("storage");
|
||||
if (st.equals("MONGODB")) {
|
||||
loadUsingMongoDB(player);
|
||||
warn("'" + StorageManager.getCurrently()+ "'");
|
||||
warn("'" + st + "'");
|
||||
}
|
||||
else {
|
||||
warn("'" + StorageManager.getCurrently()+ "'");
|
||||
warn("'" + st + "'");
|
||||
try {
|
||||
loadUsingYml(player);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
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.player.PlayerQuitEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LeaveEvent implements Listener {
|
||||
|
||||
private final PlayerConfig playerConfig;
|
||||
|
@ -18,7 +20,7 @@ public class LeaveEvent implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerLeaveEvent(PlayerQuitEvent e) {
|
||||
public void PlayerLeaveEvent(PlayerQuitEvent e) throws IOException {
|
||||
Player player = e.getPlayer();
|
||||
playerConfig.savePlayerConfig(player);
|
||||
}
|
||||
|
|
|
@ -18,13 +18,12 @@ import static gq.unurled.raxen.utils.Utils.*;
|
|||
public class StorageManager {
|
||||
|
||||
private static Raxen main;
|
||||
@Getter
|
||||
private static FileConfiguration config;
|
||||
|
||||
@Getter
|
||||
private static MongoDB mongo;
|
||||
@Getter
|
||||
private static String currently;
|
||||
@Getter
|
||||
private static Mysql mysql;
|
||||
|
||||
public StorageManager(Raxen main) {
|
||||
|
@ -39,17 +38,14 @@ public class StorageManager {
|
|||
log(s);
|
||||
if(s.equalsIgnoreCase("MONGODB")) {
|
||||
mongo.connect();
|
||||
currently = "MONGODB";
|
||||
warn("'" + s + "'");
|
||||
}
|
||||
|
||||
if(s.equalsIgnoreCase("MYSQL")) {
|
||||
error("Currently not implemented, switching to YML");
|
||||
currently = "YML";
|
||||
warn("'" + s + "'");
|
||||
}
|
||||
else {
|
||||
currently = "YML";
|
||||
warn("'" + s + "'");
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +62,13 @@ public class StorageManager {
|
|||
|
||||
if (!customFile.exists()) {
|
||||
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();
|
||||
|
@ -75,6 +77,21 @@ public class StorageManager {
|
|||
} catch (IOException | InvalidConfigurationException e) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue