Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Stockage minions avec îles + ajout is perms + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Farmeurimmo committed Jun 12, 2022
1 parent 9d8ec9e commit 0f0bf88
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 220 deletions.
23 changes: 0 additions & 23 deletions src/main/java/fr/verymc/core/storage/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public class ConfigManager {
public FileConfiguration dataAh;
public FileConfiguration dataIslands;
public FileConfiguration dataSkyblockUser;
public FileConfiguration dataMinions;
public File ahFile;
public File islandsFile;
public File skyblockUserFile;
public File minionsFile;


public File subdir;
Expand Down Expand Up @@ -67,18 +65,6 @@ public void setup() {

dataSkyblockUser = YamlConfiguration.loadConfiguration(skyblockUserFile);

minionsFile = new File(Main.instance.getDataFolder(), "minions.yml");

if (!minionsFile.exists()) {
try {
minionsFile.createNewFile();
} catch (IOException e) {
Main.instance.getLogger().info("§c§lErreur lors de la création de minions.yml");
}
}

dataMinions = YamlConfiguration.loadConfiguration(minionsFile);

/*subdir = new File(Main.instance.getDataFolder().getPath() + System.getProperty("file.separator") +
"backups");
subdir.mkdir();*/
Expand All @@ -98,10 +84,6 @@ public FileConfiguration getDataSkyblockUser() {
return dataSkyblockUser;
}

public FileConfiguration getDataMinions() {
return dataMinions;
}


public void reloadData() throws IOException {
try {
Expand All @@ -120,10 +102,5 @@ public void reloadData() throws IOException {
} catch (InvalidConfigurationException e) {
Main.instance.getLogger().info("§c§lErreur lors de la sauvegarde!");
}
try {
dataMinions.load(minionsFile);
} catch (InvalidConfigurationException e) {
Main.instance.getLogger().info("§c§lErreur lors de la sauvegarde!");
}
}
}
156 changes: 65 additions & 91 deletions src/main/java/fr/verymc/core/storage/StorageYAMLManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import main.java.fr.verymc.island.blocks.Chest;
import main.java.fr.verymc.island.challenges.IslandChallenge;
import main.java.fr.verymc.island.minions.Minion;
import main.java.fr.verymc.island.minions.MinionManager;
import main.java.fr.verymc.island.minions.MinionType;
import main.java.fr.verymc.island.perms.IslandPerms;
import main.java.fr.verymc.island.perms.IslandRanks;
Expand Down Expand Up @@ -53,40 +52,9 @@ public boolean getDataFromAPI() {

//API FETCH DATA

ArrayList<Minion> minions = new ArrayList<>();
ArrayList<Island> islands = new ArrayList<>();
ArrayList<SkyblockUser> skyblockUsers = new ArrayList<>();

for (String str : ConfigManager.instance.getDataMinions().getKeys(false)) {
if (str == null) continue;
try {
String ownerUUIDstr = ConfigManager.instance.getDataMinions().getString(str + ".uuid");
if (ownerUUIDstr == null || ownerUUIDstr.length() != 36) {
continue;
}
UUID owner = UUID.fromString(ownerUUIDstr);
MinionType minionType = MinionType.valueOf(ConfigManager.instance.getDataMinions().getString(str + ".type"));
BlockFace blockFace = BlockFace.valueOf(ConfigManager.instance.getDataMinions().getString(str + ".blFace"));
int lvl = ConfigManager.instance.getDataMinions().getInt(str + ".lvl");
Location loc = ConfigManager.instance.getDataMinions().getLocation(str + ".loc");
Location locChest = null;
if (ConfigManager.instance.getDataMinions().getLocation(str + ".locChest") != null) {
locChest = ConfigManager.instance.getDataMinions().getLocation(str + ".locChest");
}
boolean linked = ConfigManager.instance.getDataMinions().getBoolean(str + ".linked");
boolean smelft = ConfigManager.instance.getDataMinions().getBoolean(str + ".smelt");
long id = Long.parseLong(str.replace("'", ""));

Block block = (locChest == null) ? null : locChest.getBlock();
minions.add(new Minion(id, owner, lvl, loc, minionType, blockFace, linked, block, smelft));
} catch (Exception e) {
e.printStackTrace();
Bukkit.broadcastMessage("§6§lData §8» §4§lErreur lors de la récupération des données de la base de donnée sur le minion #" + str);
continue;
}
}
//DATA MINIONS

for (String str : ConfigManager.instance.getDataIslands().getKeys(false)) {
if (str == null) continue;
try {
Expand Down Expand Up @@ -202,35 +170,66 @@ public boolean getDataFromAPI() {
if (ConfigManager.instance.getDataIslands().getConfigurationSection(str + ".chests") != null) {
for (String str1 : ConfigManager.instance.getDataIslands().getConfigurationSection(str + ".chests").getKeys(false)) {
if (str1 == null) continue;
String uuidString = ConfigManager.instance.getDataIslands().getString(str + ".chests." + str1 + ".uuid");
if (uuidString == null || uuidString.length() != 36) {
try {
String uuidString = ConfigManager.instance.getDataIslands().getString(str + ".chests." + str1 + ".uuid");
if (uuidString == null || uuidString.length() != 36) {
continue;
}
UUID uuid = UUID.fromString(uuidString);
long idChest = Long.parseLong(str1.replace("'", ""));
ItemStack itemStack = ConfigManager.instance.getDataIslands().getItemStack(str + ".chests." + str1 + ".item");
int type = ConfigManager.instance.getDataIslands().getInt(str + ".chests." + str1 + ".type");
Location loc = ConfigManager.instance.getDataIslands().getLocation(str + ".chests." + str1 + ".loc");
boolean isSell = ConfigManager.instance.getDataIslands().getBoolean(str + ".chests." + str1 + ".isSell");
long chunk = ConfigManager.instance.getDataIslands().getLong(str + ".chests." + str1 + ".chunk");
double price = ConfigManager.instance.getDataIslands().getDouble(str + ".chests." + str1 + ".price");
boolean active = ConfigManager.instance.getDataIslands().getBoolean(str + ".chests." + str1 + ".active");
double amount = 0;
if (ConfigManager.instance.getDataIslands().get(str + ".chests." + str1 + ".amount") != null) {
amount = ConfigManager.instance.getDataIslands().getDouble(str + ".chests." + str1 + ".amount");
}
Material stacked = null;
if (ConfigManager.instance.getDataIslands().get(str + ".chests." + str1 + ".stacked") != null) {
stacked = Material.getMaterial(ConfigManager.instance.getDataIslands().getString(str + ".chests." + str1 + ".stacked"));
}
chests.add(new Chest(type, loc, uuid, chunk, itemStack, price, isSell, active, idChest, amount, stacked));
} catch (Exception e) {
e.printStackTrace();
Bukkit.broadcastMessage("§6§lData §8» §4§lErreur lors de la récupération des données de la base de donnée sur le chest #" + str);
continue;
}
UUID uuid = UUID.fromString(uuidString);
long idChest = Long.parseLong(str1.replace("'", ""));
ItemStack itemStack = ConfigManager.instance.getDataIslands().getItemStack(str + ".chests." + str1 + ".item");
int type = ConfigManager.instance.getDataIslands().getInt(str + ".chests." + str1 + ".type");
Location loc = ConfigManager.instance.getDataIslands().getLocation(str + ".chests." + str1 + ".loc");
boolean isSell = ConfigManager.instance.getDataIslands().getBoolean(str + ".chests." + str1 + ".isSell");
long chunk = ConfigManager.instance.getDataIslands().getLong(str + ".chests." + str1 + ".chunk");
double price = ConfigManager.instance.getDataIslands().getDouble(str + ".chests." + str1 + ".price");
boolean active = ConfigManager.instance.getDataIslands().getBoolean(str + ".chests." + str1 + ".active");
double amount = 0;
if (ConfigManager.instance.getDataIslands().get(str + ".chests." + str1 + ".amount") != null) {
amount = ConfigManager.instance.getDataIslands().getDouble(str + ".chests." + str1 + ".amount");
}
Material stacked = null;
if (ConfigManager.instance.getDataIslands().get(str + ".chests." + str1 + ".stacked") != null) {
stacked = Material.getMaterial(ConfigManager.instance.getDataIslands().getString(str + ".chests." + str1 + ".stacked"));
}
}
ArrayList<Minion> minions = new ArrayList<>();
if (ConfigManager.instance.getDataIslands().getConfigurationSection(str + ".minions") != null) {
for (String str1 : ConfigManager.instance.getDataIslands().getConfigurationSection(str + ".minions").getKeys(false)) {
if (str1 == null) continue;
try {
MinionType minionType = MinionType.valueOf(ConfigManager.instance.getDataIslands().getString(str + ".minions." + str1 + ".type"));
BlockFace blockFace = BlockFace.valueOf(ConfigManager.instance.getDataIslands().getString(str + ".minions." + str1 + ".blFace"));
int lvl = ConfigManager.instance.getDataIslands().getInt(str + ".minions." + str1 + ".lvl");
Location loc = ConfigManager.instance.getDataIslands().getLocation(str + ".minions." + str1 + ".loc");
Location locChest = null;
if (ConfigManager.instance.getDataIslands().getLocation(str + ".minions." + str1 + ".locChest") != null) {
locChest = ConfigManager.instance.getDataIslands().getLocation(str + ".minions." + str1 + ".locChest");
}
boolean linked = ConfigManager.instance.getDataIslands().getBoolean(str + ".minions." + str1 + ".linked");
boolean smelft = ConfigManager.instance.getDataIslands().getBoolean(str + ".minions." + str1 + ".smelt");
long idMinion = Long.parseLong(str1.replace("'", ""));

Block block = (locChest == null) ? null : locChest.getBlock();
minions.add(new Minion(idMinion, lvl, loc, minionType, blockFace, linked, block, smelft));
} catch (Exception e) {
e.printStackTrace();
Bukkit.broadcastMessage("§6§lData §8» §4§lErreur lors de la récupération des données de la base de donnée sur le minion #" + str);
continue;
}

chests.add(new Chest(type, loc, uuid, chunk, itemStack, price, isSell, active, idChest, amount, stacked));
}
}

islands.add(new Island(name, home, center, id, members, islandUpgradeSize, islandUpgradeMember,
color, islandBank, islandUpgradeGenerator, banneds, list, false,
permsPerRanks, isPublic, value, settings, chests));
permsPerRanks, isPublic, value, settings, chests, minions));
} catch (Exception e) {
e.printStackTrace();
continue;
Expand Down Expand Up @@ -283,9 +282,6 @@ public boolean getDataFromAPI() {
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
@Override
public void run() {
//SEND Minions to -> MinionManager.instance.minions
MinionManager.instance.minions = minions;

//SEND Islands to -> IslandManager.instance.islands
IslandManager.instance.islands = islands;

Expand All @@ -302,41 +298,6 @@ public void sendDataToAPIAuto(boolean force) {
CompletableFuture.supplyAsync(() -> {
long start = System.currentTimeMillis();

HashMap<String, Object> toSendMinions = new HashMap<>();
HashMap<String, Object> toRemoveMinions = new HashMap<>(); // NEED TO NULL Minion id because yaml don't support override data
ArrayList<Minion> minions = MinionManager.instance.minions;
for (Minion minion : minions) {
HashMap<String, Object> toSendMinion = new HashMap<>();
try {
toSendMinion.put(minion.getID() + ".uuid", minion.getOwnerUUID().toString());
toSendMinion.put(minion.getID() + ".type", minion.getMinionType().toString());
toSendMinion.put(minion.getID() + ".lvl", minion.getLevelInt());
toSendMinion.put(minion.getID() + ".blFace", minion.getBlockFace().toString());
toSendMinion.put(minion.getID() + ".loc", minion.getBlocLocation());
toSendMinion.put(minion.getID() + ".linked", minion.isChestLinked());
toSendMinion.put(minion.getID() + ".smelt", minion.isAutoSmelt());
if (minion.getChestBloc() != null) {
toSendMinion.put(minion.getID() + ".locChest", minion.getChestBloc().getLocation());
} else {
toSendMinion.put(minion.getID() + ".locChest", null);
}
} catch (Exception e) {
e.printStackTrace();
Bukkit.broadcastMessage("§6§lData §8§l» §c§lErreur lors de la lecture du minion #" + minion.getID());
toSendMinion.clear();
} finally {
if (toSendMinion.size() > 0) {
toRemoveMinions.put(minion.getID() + "", null);
toSendMinions.putAll(toSendMinion);
}
}
}
AsyncConfig.instance.setAndSaveAsyncBlockCurrentThread(toRemoveMinions, ConfigManager.instance.getDataMinions(),
ConfigManager.instance.minionsFile);
AsyncConfig.instance.setAndSaveAsync(toSendMinions, ConfigManager.instance.getDataMinions(),
ConfigManager.instance.minionsFile);


HashMap<String, Object> toSendIslands = new HashMap<>();
HashMap<String, Object> toRemoveIslands = new HashMap<>(); // NEED TO NULL Island id because yaml don't support override data
ArrayList<Island> islands = IslandManager.instance.islands;
Expand Down Expand Up @@ -393,6 +354,19 @@ public void sendDataToAPIAuto(boolean force) {
toSendIsland.put(island.getId() + ".chests." + chest.getId() + ".stacked", chest.getStacked().toString());
}
}
for (Minion minion : island.getMinions()) {
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".type", minion.getMinionType().toString());
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".lvl", minion.getLevelInt());
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".blFace", minion.getBlockFace().toString());
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".loc", minion.getBlocLocation());
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".linked", minion.isChestLinked());
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".smelt", minion.isAutoSmelt());
if (minion.getChestBloc() != null) {
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".locChest", minion.getChestBloc().getLocation());
} else {
toSendIsland.put(island.getId() + ".minions." + minion.getID() + ".locChest", null);
}
}
} catch (Exception e) {
e.printStackTrace();
Bukkit.broadcastMessage("§cErreur lors de la sauvegarde de l'île #" + island.getId());
Expand Down
Loading

0 comments on commit 0f0bf88

Please sign in to comment.