mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-02-10 08:41:22 +01:00
resolved save issue.
This commit is contained in:
parent
aa78ee51a6
commit
c91372ff40
@ -180,7 +180,6 @@ public class SkyBlock extends JavaPlugin {
|
||||
SkyBlockAPI.setImplementation(instance);
|
||||
|
||||
this.loadFromFile();
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 5000L, 5000L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -219,8 +218,6 @@ public class SkyBlock extends JavaPlugin {
|
||||
this.hologramManager.onDisable();
|
||||
}
|
||||
|
||||
this.saveToFile();
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@ -245,28 +242,6 @@ public class SkyBlock extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToFile() {
|
||||
//Save Stackables
|
||||
for (Island island : islandManager.getIslands().values()) {
|
||||
File configFile = new File(getDataFolder().toString() + "/island-data");
|
||||
FileManager.Config config = fileManager.getConfig(new File(configFile, island.getOwnerUUID() + ".yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
configLoad.set("Stackables", null);
|
||||
|
||||
if (stackableManager.getStacks() == null) return;
|
||||
for (Stackable stackable : stackableManager.getStacks().values()) {
|
||||
if (island != stackable.getIsland()) continue;
|
||||
ConfigurationSection section = configLoad.createSection("Stackables." + stackable.getUuid().toString());
|
||||
section.set("Location", stackable.getLocation());
|
||||
section.set("Material", stackable.getMaterial().name());
|
||||
section.set("Size", stackable.getSize());
|
||||
}
|
||||
try {
|
||||
config.getFileConfiguration().save(config.getFile());
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
private String formatText(String string){
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.goodandevil.skyblock.stackable;
|
||||
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import me.goodandevil.skyblock.utils.version.NMSUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Sounds;
|
||||
@ -9,6 +10,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -18,6 +21,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
@ -39,6 +43,7 @@ public class Stackable {
|
||||
this.material = material;
|
||||
updateDisplay();
|
||||
SkyBlock.getInstance().getSoundManager().playSound(location, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
save();
|
||||
}
|
||||
|
||||
public Stackable(UUID uuid, Location location, Material material, int size) {
|
||||
@ -48,6 +53,7 @@ public class Stackable {
|
||||
this.material = material;
|
||||
this.size = size;
|
||||
updateDisplay();
|
||||
save();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@ -72,6 +78,7 @@ public class Stackable {
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
save();
|
||||
}
|
||||
|
||||
public Integer getSize() {
|
||||
@ -87,12 +94,14 @@ public class Stackable {
|
||||
this.size ++;
|
||||
updateDisplay();
|
||||
SkyBlock.getInstance().getSoundManager().playSound(location, Sounds.LEVEL_UP.bukkitSound(), 1.0F, 1.0F);
|
||||
save();
|
||||
}
|
||||
|
||||
public void takeOne() {
|
||||
this.size --;
|
||||
updateDisplay();
|
||||
SkyBlock.getInstance().getSoundManager().playSound(location, Sounds.ARROW_HIT.bukkitSound(), 1.0F, 1.0F);
|
||||
save();
|
||||
}
|
||||
|
||||
private void updateDisplay() {
|
||||
@ -119,4 +128,15 @@ public class Stackable {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
File configFile = new File(SkyBlock.getInstance().getDataFolder().toString() + "/island-data");
|
||||
FileManager.Config config = SkyBlock.getInstance().getFileManager().getConfig(new File(configFile, island.getOwnerUUID() + ".yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
ConfigurationSection section = configLoad.createSection("Stackables." + getUuid().toString());
|
||||
section.set("Location", getLocation());
|
||||
section.set("Material", getMaterial().name());
|
||||
section.set("Size", getSize());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user