1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Improvements to error logging in world loading

This commit is contained in:
TheBusyBiscuit 2020-06-22 01:55:11 +02:00
parent f8182e4e3b
commit a06e49cf13
3 changed files with 114 additions and 98 deletions

View File

@ -35,6 +35,8 @@
#### Fixes
* Fixed #2005
* Fixed #2009
* Fixed a chunk caching issue for GEO resources
* Fixed Infused Magnet working even if you haven't researched it
## Release Candidate 13 (16 Jun 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13

View File

@ -308,17 +308,17 @@ public final class PlayerProfile {
}
public void sendStats(CommandSender sender) {
Set<Research> researched = getResearches();
int levels = researched.stream().mapToInt(Research::getCost).sum();
int totalResearches = SlimefunPlugin.getRegistry().getResearches().size();
Set<Research> unlockedResearches = getResearches();
int levels = unlockedResearches.stream().mapToInt(Research::getCost).sum();
int allResearches = SlimefunPlugin.getRegistry().getResearches().size();
float progress = Math.round(((researched.size() * 100.0F) / totalResearches) * 100.0F) / 100.0F;
float progress = Math.round(((unlockedResearches.size() * 100.0F) / allResearches) * 100.0F) / 100.0F;
sender.sendMessage("");
sender.sendMessage(ChatColors.color("&7Statistics for Player: &b" + name));
sender.sendMessage("");
sender.sendMessage(ChatColors.color("&7Title: " + ChatColor.AQUA + getTitle()));
sender.sendMessage(ChatColors.color("&7Research Progress: " + NumberUtils.getColorFromPercentage(progress) + progress + " &r% " + ChatColor.YELLOW + '(' + researched.size() + " / " + totalResearches + ')'));
sender.sendMessage(ChatColors.color("&7Research Progress: " + NumberUtils.getColorFromPercentage(progress) + progress + " &r% " + ChatColor.YELLOW + '(' + unlockedResearches.size() + " / " + allResearches + ')'));
sender.sendMessage(ChatColors.color("&7Total XP Levels spent: " + ChatColor.AQUA + levels));
}
@ -347,14 +347,14 @@ public final class PlayerProfile {
}
/**
* Get the PlayerProfile for a player asynchronously.
* Get the {@link PlayerProfile} for a {@link OfflinePlayer} asynchronously.
*
* @param p
* The player who's profile to retrieve
* The {@link OfflinePlayer} who's {@link PlayerProfile} to retrieve
* @param callback
* The callback with the PlayerProfile
* The callback with the {@link PlayerProfile}
*
* @return If the player was cached or not.
* @return If the {@link OfflinePlayer} was cached or not.
*/
public static boolean get(OfflinePlayer p, Consumer<PlayerProfile> callback) {
Validate.notNull(p, "Cannot get a PlayerProfile for: null!");

View File

@ -40,7 +40,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
// This class really needs a big overhaul
// This class really needs a VERY big overhaul
public class BlockStorage {
private static final String PATH_BLOCKS = "data-storage/Slimefun/stored-blocks/";
@ -52,6 +52,9 @@ public class BlockStorage {
private final Map<Location, BlockMenu> inventories = new ConcurrentHashMap<>();
private final Map<String, Config> blocksCache = new ConcurrentHashMap<>();
private static int chunkChanges = 0;
private int changes = 0;
public static BlockStorage getStorage(World world) {
return SlimefunPlugin.getRegistry().getWorlds().get(world.getName());
}
@ -105,7 +108,20 @@ public class BlockStorage {
File dir = new File(PATH_BLOCKS + w.getName());
if (dir.exists()) {
long total = dir.listFiles().length;
loadBlocks(dir);
}
else {
dir.mkdirs();
}
loadChunks();
loadInventories();
SlimefunPlugin.getRegistry().getWorlds().put(world.getName(), this);
}
private void loadBlocks(File directory) {
long total = directory.listFiles().length;
long start = System.currentTimeMillis();
long done = 0;
long timestamp = System.currentTimeMillis();
@ -113,17 +129,16 @@ public class BlockStorage {
int delay = SlimefunPlugin.getCfg().getInt("URID.info-delay");
try {
for (File file : dir.listFiles()) {
for (File file : directory.listFiles()) {
if (file.getName().equals("null.sfb")) {
Slimefun.getLogger().log(Level.WARNING, "Corrupted file detected!");
Slimefun.getLogger().log(Level.WARNING, "Slimefun will simply skip this File, but you");
Slimefun.getLogger().log(Level.WARNING, "should maybe look into it!");
Slimefun.getLogger().log(Level.WARNING, "File with corrupted blocks detected!");
Slimefun.getLogger().log(Level.WARNING, "Slimefun will simply skip this File, you should look inside though!");
Slimefun.getLogger().log(Level.WARNING, file.getPath());
}
else if (file.getName().endsWith(".sfb")) {
if (timestamp + delay < System.currentTimeMillis()) {
int progress = Math.round((((done * 100.0F) / total) * 100.0F) / 100.0F);
Slimefun.getLogger().log(Level.INFO, "Loading Blocks... {0}% done (\"{1}\")", new Object[] { progress, w.getName() });
Slimefun.getLogger().log(Level.INFO, "Loading Blocks... {0}% done (\"{1}\")", new Object[] { progress, world.getName() });
timestamp = System.currentTimeMillis();
}
@ -180,10 +195,8 @@ public class BlockStorage {
}
}
}
else {
dir.mkdirs();
}
private void loadChunks() {
File chunks = new File(PATH_CHUNKS + "chunks.sfc");
if (chunks.exists()) {
@ -200,15 +213,14 @@ public class BlockStorage {
}
}
}
}
SlimefunPlugin.getRegistry().getWorlds().put(world.getName(), this);
private void loadInventories() {
for (File file : new File("data-storage/Slimefun/stored-inventories").listFiles()) {
if (file.getName().startsWith(w.getName()) && file.getName().endsWith(".sfi")) {
if (file.getName().startsWith(world.getName()) && file.getName().endsWith(".sfi")) {
try {
Location l = deserializeLocation(file.getName().replace(".sfi", ""));
io.github.thebusybiscuit.cscorelib2.config.Config cfg = new io.github.thebusybiscuit.cscorelib2.config.Config(file);
try {
BlockMenuPreset preset = BlockMenuPreset.getPreset(cfg.getString("preset"));
if (preset == null) {
@ -220,13 +232,14 @@ public class BlockStorage {
}
}
catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while loading this Inventory: " + file.getName());
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while loading this Block Inventory: " + file.getName());
}
}
}
for (File file : new File("data-storage/Slimefun/universal-inventories").listFiles()) {
if (file.getName().endsWith(".sfi")) {
try {
io.github.thebusybiscuit.cscorelib2.config.Config cfg = new io.github.thebusybiscuit.cscorelib2.config.Config(file);
BlockMenuPreset preset = BlockMenuPreset.getPreset(cfg.getString("preset"));
@ -234,11 +247,12 @@ public class BlockStorage {
SlimefunPlugin.getRegistry().getUniversalInventories().put(preset.getID(), new UniversalBlockMenu(preset, cfg));
}
}
catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while loading this universal Inventory: " + file.getName());
}
}
}
}
private static int chunkChanges = 0;
private int changes = 0;
public void computeChanges() {
changes = blocksCache.size() + chunkChanges;