1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] Refactoring

This commit is contained in:
TheBusyBiscuit 2021-01-10 16:21:15 +01:00
parent 177637d070
commit f3ed8c0451
29 changed files with 111 additions and 107 deletions

View File

@ -10,7 +10,6 @@ import org.apache.commons.lang.Validate;
import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This class represents a Setting for a {@link SlimefunItem} that can be modified via * This class represents a Setting for a {@link SlimefunItem} that can be modified via
@ -152,19 +151,19 @@ public class ItemSetting<T> {
if (validateInput(newValue)) { if (validateInput(newValue)) {
this.value = newValue; this.value = newValue;
} else { } else {
Slimefun.getLogger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!"); SlimefunPlugin.logger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!");
Slimefun.getLogger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getId(), getKey() }); SlimefunPlugin.logger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getId(), getKey() });
Slimefun.getLogger().log(Level.WARNING, "{0} is not a valid input!", configuredValue); SlimefunPlugin.logger().log(Level.WARNING, "{0} is not a valid input!", configuredValue);
Slimefun.getLogger().log(Level.WARNING, getErrorMessage()); SlimefunPlugin.logger().log(Level.WARNING, getErrorMessage());
} }
} else { } else {
this.value = defaultValue; this.value = defaultValue;
String found = configuredValue == null ? "null" : configuredValue.getClass().getSimpleName(); String found = configuredValue == null ? "null" : configuredValue.getClass().getSimpleName();
Slimefun.getLogger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!"); SlimefunPlugin.logger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!");
Slimefun.getLogger().log(Level.WARNING, "Please only use settings that are valid."); SlimefunPlugin.logger().log(Level.WARNING, "Please only use settings that are valid.");
Slimefun.getLogger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getId(), getKey() }); SlimefunPlugin.logger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getId(), getKey() });
Slimefun.getLogger().log(Level.WARNING, "Expected \"{0}\" but found: \"{1}\"", new Object[] { defaultValue.getClass().getSimpleName(), found }); SlimefunPlugin.logger().log(Level.WARNING, "Expected \"{0}\" but found: \"{1}\"", new Object[] { defaultValue.getClass().getSimpleName(), found });
} }
} }

View File

@ -43,7 +43,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* A class that can store a Player's {@link Research} progress for caching purposes. * A class that can store a Player's {@link Research} progress for caching purposes.
@ -96,7 +95,7 @@ public final class PlayerProfile {
waypoints.add(new Waypoint(this, key, loc, waypointName)); waypoints.add(new Waypoint(this, key, loc, waypointName));
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, x, () -> "Could not load Waypoint \"" + key + "\" for Player \"" + p.getName() + '"'); SlimefunPlugin.logger().log(Level.WARNING, x, () -> "Could not load Waypoint \"" + key + "\" for Player \"" + p.getName() + '"');
} }
} }
} }

View File

@ -94,7 +94,7 @@ public class LockedCategory extends Category {
} }
for (NamespacedKey key : namespacedKeys) { for (NamespacedKey key : namespacedKeys) {
Slimefun.getLogger().log(Level.INFO, "Parent \"{0}\" for Category \"{1}\" was not found, probably just disabled.", new Object[] { key, getKey() }); SlimefunPlugin.logger().log(Level.INFO, "Parent \"{0}\" for Category \"{1}\" was not found, probably just disabled.", new Object[] { key, getKey() });
} }
} }

View File

@ -20,7 +20,6 @@ import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* The {@link CargoNet} is a type of {@link Network} which deals with {@link ItemStack} transportation. * The {@link CargoNet} is a type of {@link Network} which deals with {@link ItemStack} transportation.
@ -250,7 +249,7 @@ public class CargoNet extends AbstractItemNetwork {
String str = BlockStorage.getLocationInfo(node).getString("frequency"); String str = BlockStorage.getLocationInfo(node).getString("frequency");
return str == null ? 0 : Integer.parseInt(str); return str == null ? 0 : Integer.parseInt(str);
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while parsing a Cargo Node Frequency (" + node.getWorld().getName() + " - " + node.getBlockX() + "," + node.getBlockY() + "," + +node.getBlockZ() + ")"); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while parsing a Cargo Node Frequency (" + node.getWorld().getName() + " - " + node.getBlockX() + "," + node.getBlockY() + "," + +node.getBlockZ() + ")");
return 0; return 0;
} }
} }

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This Service is responsible for automatically saving {@link Player} and {@link Block} * This Service is responsible for automatically saving {@link Player} and {@link Block}
@ -66,7 +65,7 @@ public class AutoSavingService {
} }
if (players > 0) { if (players > 0) {
Slimefun.getLogger().log(Level.INFO, "Auto-saved all player data for {0} player(s)!", players); SlimefunPlugin.logger().log(Level.INFO, "Auto-saved all player data for {0} player(s)!", players);
} }
} }
@ -89,7 +88,7 @@ public class AutoSavingService {
} }
if (!worlds.isEmpty()) { if (!worlds.isEmpty()) {
Slimefun.getLogger().log(Level.INFO, "Auto-saving block data... (Next auto-save: {0}m)", interval); SlimefunPlugin.logger().log(Level.INFO, "Auto-saving block data... (Next auto-save: {0}m)", interval);
for (BlockStorage storage : worlds) { for (BlockStorage storage : worlds) {
storage.save(); storage.save();

View File

@ -20,7 +20,6 @@ import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This Service creates a Backup of your Slimefun world data on every server shutdown. * This Service creates a Backup of your Slimefun world data on every server shutdown.
@ -43,7 +42,7 @@ public class BackupService implements Runnable {
try { try {
purgeBackups(backups); purgeBackups(backups);
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.WARNING, "Could not delete an old backup", e); SlimefunPlugin.logger().log(Level.WARNING, "Could not delete an old backup", e);
} }
} }
@ -56,12 +55,12 @@ public class BackupService implements Runnable {
createBackup(output); createBackup(output);
} }
Slimefun.getLogger().log(Level.INFO, "Backed up Slimefun data to: {0}", file.getName()); SlimefunPlugin.logger().log(Level.INFO, "Backed up Slimefun data to: {0}", file.getName());
} else { } else {
Slimefun.getLogger().log(Level.WARNING, "Could not create backup-file: {0}", file.getName()); SlimefunPlugin.logger().log(Level.WARNING, "Could not create backup-file: {0}", file.getName());
} }
} catch (IOException x) { } catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while creating a backup for Slimefun " + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while creating a backup for Slimefun " + SlimefunPlugin.getVersion());
} }
} }
} }

View File

@ -19,8 +19,8 @@ import org.bukkit.persistence.PersistentDataHolder;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* The {@link BlockDataService} is similar to the {@link CustomItemDataService}, * The {@link BlockDataService} is similar to the {@link CustomItemDataService},
@ -78,12 +78,12 @@ public class BlockDataService implements Keyed {
container.set(namespacedKey, PersistentDataType.STRING, value); container.set(namespacedKey, PersistentDataType.STRING, value);
state.update(); state.update();
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "Please check if your Server Software is up to date!"); SlimefunPlugin.logger().log(Level.SEVERE, "Please check if your Server Software is up to date!");
String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName(); String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName();
Slimefun.getLogger().log(Level.SEVERE, () -> serverSoftware + " | " + Bukkit.getVersion() + " | " + Bukkit.getBukkitVersion()); SlimefunPlugin.logger().log(Level.SEVERE, () -> serverSoftware + " | " + Bukkit.getVersion() + " | " + Bukkit.getBukkitVersion());
Slimefun.getLogger().log(Level.SEVERE, "An Exception was thrown while trying to set Persistent Data for a Block", x); SlimefunPlugin.logger().log(Level.SEVERE, "An Exception was thrown while trying to set Persistent Data for a Block", x);
} }
} }
} }

View File

@ -27,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization; import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* As the name suggests, this Service is responsible for Localization. * As the name suggests, this Service is responsible for Localization.
@ -78,7 +77,7 @@ public class LocalizationService extends SlimefunLocalization {
plugin.getLogger().log(Level.WARNING, "Could not recognize the given language: \"{0}\"", serverDefaultLanguage); plugin.getLogger().log(Level.WARNING, "Could not recognize the given language: \"{0}\"", serverDefaultLanguage);
} }
Slimefun.getLogger().log(Level.INFO, "Available languages: {0}", String.join(", ", languages.keySet())); SlimefunPlugin.logger().log(Level.INFO, "Available languages: {0}", String.join(", ", languages.keySet()));
save(); save();
} else { } else {
translationsEnabled = false; translationsEnabled = false;
@ -178,7 +177,7 @@ public class LocalizationService extends SlimefunLocalization {
defaultLanguage.setCategoriesFile(streamConfigFile("categories_" + language + ".yml", null)); defaultLanguage.setCategoriesFile(streamConfigFile("categories_" + language + ".yml", null));
defaultLanguage.setRecipeTypesFile(streamConfigFile("recipes_" + language + ".yml", null)); defaultLanguage.setRecipeTypesFile(streamConfigFile("recipes_" + language + ".yml", null));
Slimefun.getLogger().log(Level.INFO, "Loaded language \"{0}\"", language); SlimefunPlugin.logger().log(Level.INFO, "Loaded language \"{0}\"", language);
getConfig().setValue(LANGUAGE_PATH, language); getConfig().setValue(LANGUAGE_PATH, language);
// Loading in the defaults from our resources folder // Loading in the defaults from our resources folder
@ -188,7 +187,7 @@ public class LocalizationService extends SlimefunLocalization {
FileConfiguration config = YamlConfiguration.loadConfiguration(reader); FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
getConfig().getConfiguration().setDefaults(config); getConfig().getConfiguration().setDefaults(config);
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to load language file: \"" + path + "\""); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "Failed to load language file: \"" + path + "\"");
} }
save(); save();
@ -280,7 +279,7 @@ public class LocalizationService extends SlimefunLocalization {
return config; return config;
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to load language file into memory: \"" + path + "\""); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "Failed to load language file into memory: \"" + path + "\"");
return null; return null;
} }
} }

View File

@ -9,10 +9,10 @@ import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import kong.unirest.JsonNode; import kong.unirest.JsonNode;
import kong.unirest.json.JSONArray; import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject; import kong.unirest.json.JSONObject;
import me.mrCookieSlime.Slimefun.api.Slimefun;
class ContributionsConnector extends GitHubConnector { class ContributionsConnector extends GitHubConnector {
@ -84,7 +84,7 @@ class ContributionsConnector extends GitHubConnector {
if (response.isArray()) { if (response.isArray()) {
computeContributors(response.getArray()); computeContributors(response.getArray());
} else { } else {
Slimefun.getLogger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response); SlimefunPlugin.logger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response);
} }
} }

View File

@ -181,10 +181,10 @@ public class Contributor {
public String getTexture() { public String getTexture() {
if (!headTexture.isComputed() || !headTexture.isPresent()) { if (!headTexture.isComputed() || !headTexture.isPresent()) {
GitHubService github = SlimefunPlugin.getGitHubService(); GitHubService github = SlimefunPlugin.getGitHubService();
if (github != null) {
String cached = github.getCachedTexture(githubUsername); String cached = github.getCachedTexture(githubUsername);
return cached != null ? cached : HeadTexture.UNKNOWN.getTexture();
if (cached != null) {
return cached;
} else { } else {
return HeadTexture.UNKNOWN.getTexture(); return HeadTexture.UNKNOWN.getTexture();
} }

View File

@ -14,12 +14,12 @@ import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import kong.unirest.HttpResponse; import kong.unirest.HttpResponse;
import kong.unirest.JsonNode; import kong.unirest.JsonNode;
import kong.unirest.Unirest; import kong.unirest.Unirest;
import kong.unirest.UnirestException; import kong.unirest.UnirestException;
import kong.unirest.json.JSONException; import kong.unirest.json.JSONException;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* The {@link GitHubConnector} is used to connect to the GitHub API service. * The {@link GitHubConnector} is used to connect to the GitHub API service.
@ -100,7 +100,7 @@ abstract class GitHubConnector {
file = new File("plugins/Slimefun/cache/github/" + getFileName() + ".json"); file = new File("plugins/Slimefun/cache/github/" + getFileName() + ".json");
if (github.isLoggingEnabled()) { if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.INFO, "Retrieving {0}.json from GitHub...", getFileName()); SlimefunPlugin.logger().log(Level.INFO, "Retrieving {0}.json from GitHub...", getFileName());
} }
try { try {
@ -116,7 +116,7 @@ abstract class GitHubConnector {
writeCacheFile(response.getBody()); writeCacheFile(response.getBody());
} else { } else {
if (github.isLoggingEnabled()) { if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { url, response.getStatus(), response.getBody() }); SlimefunPlugin.logger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { url, response.getStatus(), response.getBody() });
} }
// It has the cached file, let's just read that then // It has the cached file, let's just read that then
@ -130,7 +130,7 @@ abstract class GitHubConnector {
} }
} catch (UnirestException e) { } catch (UnirestException e) {
if (github.isLoggingEnabled()) { if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.WARNING, "Could not connect to GitHub in time.", e); SlimefunPlugin.logger().log(Level.WARNING, "Could not connect to GitHub in time.", e);
} }
// It has the cached file, let's just read that then // It has the cached file, let's just read that then
@ -153,7 +153,7 @@ abstract class GitHubConnector {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
return new JsonNode(reader.readLine()); return new JsonNode(reader.readLine());
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
Slimefun.getLogger().log(Level.WARNING, "Failed to read Github cache file: {0} - {1}: {2}", new Object[] { file.getName(), e.getClass().getSimpleName(), e.getMessage() }); SlimefunPlugin.logger().log(Level.WARNING, "Failed to read Github cache file: {0} - {1}: {2}", new Object[] { file.getName(), e.getClass().getSimpleName(), e.getMessage() });
return null; return null;
} }
} }
@ -162,7 +162,7 @@ abstract class GitHubConnector {
try (FileOutputStream output = new FileOutputStream(file)) { try (FileOutputStream output = new FileOutputStream(file)) {
output.write(node.toString().getBytes(StandardCharsets.UTF_8)); output.write(node.toString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.WARNING, "Failed to populate GitHub cache: {0} - {1}", new Object[] { e.getClass().getSimpleName(), e.getMessage() }); SlimefunPlugin.logger().log(Level.WARNING, "Failed to populate GitHub cache: {0} - {1}", new Object[] { e.getClass().getSimpleName(), e.getMessage() });
} }
} }
} }

View File

@ -7,10 +7,10 @@ import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import kong.unirest.JsonNode; import kong.unirest.JsonNode;
import kong.unirest.json.JSONArray; import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject; import kong.unirest.json.JSONObject;
import me.mrCookieSlime.Slimefun.api.Slimefun;
class GitHubIssuesConnector extends GitHubConnector { class GitHubIssuesConnector extends GitHubConnector {
@ -42,7 +42,7 @@ class GitHubIssuesConnector extends GitHubConnector {
callback.accept(issues, pullRequests); callback.accept(issues, pullRequests);
} else { } else {
Slimefun.getLogger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response); SlimefunPlugin.logger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response);
} }
} }

View File

@ -16,7 +16,6 @@ import org.bukkit.Bukkit;
import io.github.thebusybiscuit.cscorelib2.players.MinecraftAccount; import io.github.thebusybiscuit.cscorelib2.players.MinecraftAccount;
import io.github.thebusybiscuit.cscorelib2.players.MinecraftAccount.TooManyRequestsException; import io.github.thebusybiscuit.cscorelib2.players.MinecraftAccount.TooManyRequestsException;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This {@link GitHubTask} represents a {@link Runnable} that is run every X minutes. * This {@link GitHubTask} represents a {@link Runnable} that is run every X minutes.
@ -101,8 +100,8 @@ class GitHubTask implements Runnable {
contributor.setTexture(null); contributor.setTexture(null);
} catch (IOException x) { } catch (IOException x) {
// Too many requests // Too many requests
Slimefun.getLogger().log(Level.WARNING, "Attempted to connect to mojang.com, got this response: {0}: {1}", new Object[] { x.getClass().getSimpleName(), x.getMessage() }); SlimefunPlugin.logger().log(Level.WARNING, "Attempted to connect to mojang.com, got this response: {0}: {1}", new Object[] { x.getClass().getSimpleName(), x.getMessage() });
Slimefun.getLogger().log(Level.WARNING, "This usually means mojang.com is temporarily down or started to rate-limit this connection, this is not an error message!"); SlimefunPlugin.logger().log(Level.WARNING, "This usually means mojang.com is temporarily down or started to rate-limit this connection, this is not an error message!");
// Retry after 5 minutes if it was rate-limiting // Retry after 5 minutes if it was rate-limiting
if (x.getMessage().contains("429")) { if (x.getMessage().contains("429")) {
@ -111,7 +110,7 @@ class GitHubTask implements Runnable {
return -1; return -1;
} catch (TooManyRequestsException x) { } catch (TooManyRequestsException x) {
Slimefun.getLogger().log(Level.WARNING, "Received a rate-limit from mojang.com, retrying in 4 minutes"); SlimefunPlugin.logger().log(Level.WARNING, "Received a rate-limit from mojang.com, retrying in 4 minutes");
Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance(), this::grabTextures, 4 * 60 * 20L); Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance(), this::grabTextures, 4 * 60 * 20L);
return -1; return -1;

View File

@ -26,7 +26,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask; import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is * The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is
@ -192,7 +191,7 @@ public class SlimefunProfiler {
return; return;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Slimefun.getLogger().log(Level.SEVERE, "A Profiler Thread was interrupted", e); SlimefunPlugin.logger().log(Level.SEVERE, "A Profiler Thread was interrupted", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -694,6 +695,19 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance; return instance;
} }
/**
* This returns the {@link Logger} instance that Slimefun uses.
* <p>
* <strong>Any {@link SlimefunAddon} should use their own {@link Logger} instance!</strong>
*
* @return Our {@link Logger} instance
*/
@Nonnull
public static Logger logger() {
validateInstance();
return instance.getLogger();
}
/** /**
* This returns the version of Slimefun that is currently installed. * This returns the version of Slimefun that is currently installed.
* *

View File

@ -698,7 +698,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
private void printErrorMessage(Player p, Throwable x) { private void printErrorMessage(Player p, Throwable x) {
p.sendMessage(ChatColor.DARK_RED + "An internal server error has occurred. Please inform an admin, check the console for further info."); p.sendMessage(ChatColor.DARK_RED + "An internal server error has occurred. Please inform an admin, check the console for further info.");
Slimefun.getLogger().log(Level.SEVERE, "An error has occurred while trying to open a SlimefunItem in the guide!", x); SlimefunPlugin.logger().log(Level.SEVERE, "An error has occurred while trying to open a SlimefunItem in the guide!", x);
} }
} }

View File

@ -58,7 +58,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -425,7 +424,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
openScriptEditor(player, b); openScriptEditor(player, b);
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Exception was thrown when a User tried to download a Script!", x); SlimefunPlugin.logger().log(Level.SEVERE, "An Exception was thrown when a User tried to download a Script!", x);
} }
return false; return false;

View File

@ -21,9 +21,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* A {@link Script} represents runnable code for a {@link ProgrammableAndroid}. * A {@link Script} represents runnable code for a {@link ProgrammableAndroid}.
@ -244,7 +244,7 @@ public final class Script {
scripts.add(new Script(config)); scripts.add(new Script(config));
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Exception occurred while trying to load Android Script '" + file.getName() + "'"); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Exception occurred while trying to load Android Script '" + file.getName() + "'");
} }
} }
} }

View File

@ -17,8 +17,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/** /**
@ -42,7 +42,7 @@ public class MagicianTalisman extends Talisman {
enchantments.add(new TalismanEnchantment(enchantment, i)); enchantments.add(new TalismanEnchantment(enchantment, i));
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "The following Exception occurred while trying to register the following Enchantment: " + enchantment); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "The following Exception occurred while trying to register the following Enchantment: " + enchantment);
} }
} }

View File

@ -27,7 +27,6 @@ import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This represents a running instance of an {@link IndustrialMiner}. * This represents a running instance of an {@link IndustrialMiner}.
@ -198,7 +197,7 @@ class ActiveMiner implements Runnable {
nextColumn(); nextColumn();
} catch (Exception e) { } catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occurred while running an Industrial Miner at " + new BlockPosition(chest)); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "An Error occurred while running an Industrial Miner at " + new BlockPosition(chest));
stop(); stop();
} }
}); });
@ -350,7 +349,7 @@ class ActiveMiner implements Runnable {
stop("machines.INDUSTRIAL_MINER.destroyed"); stop("machines.INDUSTRIAL_MINER.destroyed");
} }
} catch (Exception e) { } catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block)); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block));
stop(); stop();
} }
} }

View File

@ -29,7 +29,6 @@ import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This {@link Listener} is responsible for handling our debugging tool, the debug fish. * This {@link Listener} is responsible for handling our debugging tool, the debug fish.
@ -99,7 +98,7 @@ public class DebugFishListener implements Listener {
try { try {
sendInfo(p, b); sendInfo(p, b);
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Exception occurred while using a Debug-Fish", x); SlimefunPlugin.logger().log(Level.SEVERE, "An Exception occurred while using a Debug-Fish", x);
} }
} }
} }

View File

@ -11,7 +11,6 @@ import org.bukkit.event.world.WorldUnloadEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public class WorldListener implements Listener { public class WorldListener implements Listener {
@ -32,7 +31,7 @@ public class WorldListener implements Listener {
if (storage != null) { if (storage != null) {
storage.saveAndRemove(); storage.saveAndRemove();
} else { } else {
Slimefun.getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", e.getWorld().getName()); SlimefunPlugin.logger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", e.getWorld().getName());
} }
} }

View File

@ -35,14 +35,13 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smelt
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class PostSetup { public final class PostSetup {
private PostSetup() {} private PostSetup() {}
public static void setupWiki() { public static void setupWiki() {
Slimefun.getLogger().log(Level.INFO, "Loading Wiki pages..."); SlimefunPlugin.logger().log(Level.INFO, "Loading Wiki pages...");
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(SlimefunPlugin.class.getResourceAsStream("/wiki.json"), StandardCharsets.UTF_8))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(SlimefunPlugin.class.getResourceAsStream("/wiki.json"), StandardCharsets.UTF_8))) {
@ -57,7 +56,7 @@ public final class PostSetup {
} }
} }
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to load wiki.json file", e); SlimefunPlugin.logger().log(Level.SEVERE, "Failed to load wiki.json file", e);
} }
} }
@ -68,7 +67,7 @@ public final class PostSetup {
SlimefunItem item = iterator.next(); SlimefunItem item = iterator.next();
if (item == null) { if (item == null) {
Slimefun.getLogger().log(Level.WARNING, "Removed bugged Item ('NULL?')"); SlimefunPlugin.logger().log(Level.WARNING, "Removed bugged Item ('NULL?')");
iterator.remove(); iterator.remove();
} else { } else {
try { try {

View File

@ -12,7 +12,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterLis
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup; import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This Task initializes all items, some listeners and various other stuff. * This Task initializes all items, some listeners and various other stuff.
@ -54,7 +53,7 @@ public class SlimefunStartupTask implements Runnable {
try { try {
new BlockStorage(world); new BlockStorage(world);
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while trying to load World \"" + world.getName() + "\" for Slimefun v" + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while trying to load World \"" + world.getName() + "\" for Slimefun v" + SlimefunPlugin.getVersion());
} }
} }

View File

@ -27,7 +27,6 @@ import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* The {@link TickerTask} is responsible for ticking every {@link BlockTicker}, * The {@link TickerTask} is responsible for ticking every {@link BlockTicker},
@ -132,7 +131,7 @@ public class TickerTask implements Runnable {
reset(); reset();
SlimefunPlugin.getProfiler().stop(); SlimefunPlugin.getProfiler().stop();
} catch (Exception | LinkageError x) { } catch (Exception | LinkageError x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Exception was caught while ticking the Block Tickers Task for Slimefun v" + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Exception was caught while ticking the Block Tickers Task for Slimefun v" + SlimefunPlugin.getVersion());
reset(); reset();
} }
} }
@ -147,7 +146,7 @@ public class TickerTask implements Runnable {
} }
} }
} catch (ArrayIndexOutOfBoundsException | NumberFormatException x) { } catch (ArrayIndexOutOfBoundsException | NumberFormatException x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Exception has occurred while trying to resolve Chunk: " + chunk); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Exception has occurred while trying to resolve Chunk: " + chunk);
} }
} }
@ -204,10 +203,10 @@ public class TickerTask implements Runnable {
new ErrorReport<>(x, l, item); new ErrorReport<>(x, l, item);
bugs.put(position, errors); bugs.put(position, errors);
} else if (errors == 4) { } else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: {0} Y: {1} Z: {2} ({3})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), item.getId() }); SlimefunPlugin.logger().log(Level.SEVERE, "X: {0} Y: {1} Z: {2} ({3})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), item.getId() });
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 error messages in the last 4 Ticks, the Block has been terminated."); SlimefunPlugin.logger().log(Level.SEVERE, "has thrown 4 error messages in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details."); SlimefunPlugin.logger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " "); SlimefunPlugin.logger().log(Level.SEVERE, " ");
bugs.remove(position); bugs.remove(position);
BlockStorage.deleteLocationInfoUnsafely(l, true); BlockStorage.deleteLocationInfoUnsafely(l, true);

View File

@ -16,7 +16,6 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import dev.lone.itemsadder.api.ItemsAdder; import dev.lone.itemsadder.api.ItemsAdder;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/** /**
* This Service holds all interactions and hooks with third-party {@link Plugin Plugins} * This Service holds all interactions and hooks with third-party {@link Plugin Plugins}
@ -133,7 +132,7 @@ public class IntegrationsManager {
private boolean isAddonInstalled(@Nonnull String addon) { private boolean isAddonInstalled(@Nonnull String addon) {
if (plugin.getServer().getPluginManager().isPluginEnabled(addon)) { if (plugin.getServer().getPluginManager().isPluginEnabled(addon)) {
Slimefun.getLogger().log(Level.INFO, "Hooked into Slimefun Addon: {0}", addon); SlimefunPlugin.logger().log(Level.INFO, "Hooked into Slimefun Addon: {0}", addon);
return true; return true;
} else { } else {
return false; return false;
@ -154,14 +153,14 @@ public class IntegrationsManager {
if (integration != null && integration.isEnabled()) { if (integration != null && integration.isEnabled()) {
String version = integration.getDescription().getVersion(); String version = integration.getDescription().getVersion();
Slimefun.getLogger().log(Level.INFO, "Hooked into Plugin: {0} v{1}", new Object[] { pluginName, version }); SlimefunPlugin.logger().log(Level.INFO, "Hooked into Plugin: {0} v{1}", new Object[] { pluginName, version });
try { try {
// Run our callback // Run our callback
consumer.accept(integration); consumer.accept(integration);
} catch (Exception | LinkageError x) { } catch (Exception | LinkageError x) {
Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating {0} or Slimefun?", pluginName); SlimefunPlugin.logger().log(Level.WARNING, "Maybe consider updating {0} or Slimefun?", pluginName);
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into " + pluginName + " v" + version); SlimefunPlugin.logger().log(Level.WARNING, x, () -> "Failed to hook into " + pluginName + " v" + version);
} }
} }
} }

View File

@ -97,7 +97,7 @@ public class BlockStorage {
return new Location(w, Integer.parseInt(components[1]), Integer.parseInt(components[2]), Integer.parseInt(components[3])); return new Location(w, Integer.parseInt(components[1]), Integer.parseInt(components[2]), Integer.parseInt(components[3]));
} }
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
Slimefun.getLogger().log(Level.WARNING, "Could not parse Number", x); SlimefunPlugin.logger().log(Level.WARNING, "Could not parse Number", x);
} }
return null; return null;
} }
@ -114,8 +114,8 @@ public class BlockStorage {
return; return;
} }
Slimefun.getLogger().log(Level.INFO, "Loading Blocks for World \"{0}\"", w.getName()); SlimefunPlugin.logger().log(Level.INFO, "Loading Blocks for World \"{0}\"", w.getName());
Slimefun.getLogger().log(Level.INFO, "This may take a long time..."); SlimefunPlugin.logger().log(Level.INFO, "This may take a long time...");
File dir = new File(PATH_BLOCKS + w.getName()); File dir = new File(PATH_BLOCKS + w.getName());
@ -142,13 +142,13 @@ public class BlockStorage {
try { try {
for (File file : directory.listFiles()) { for (File file : directory.listFiles()) {
if (file.getName().equals("null.sfb")) { if (file.getName().equals("null.sfb")) {
Slimefun.getLogger().log(Level.WARNING, "File with corrupted blocks detected!"); SlimefunPlugin.logger().log(Level.WARNING, "File with corrupted blocks detected!");
Slimefun.getLogger().log(Level.WARNING, "Slimefun will simply skip this File, you should look inside though!"); SlimefunPlugin.logger().log(Level.WARNING, "Slimefun will simply skip this File, you should look inside though!");
Slimefun.getLogger().log(Level.WARNING, file.getPath()); SlimefunPlugin.logger().log(Level.WARNING, file.getPath());
} else if (file.getName().endsWith(".sfb")) { } else if (file.getName().endsWith(".sfb")) {
if (timestamp + delay < System.currentTimeMillis()) { if (timestamp + delay < System.currentTimeMillis()) {
int progress = Math.round((((done * 100.0F) / total) * 100.0F) / 100.0F); 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, world.getName() }); SlimefunPlugin.logger().log(Level.INFO, "Loading Blocks... {0}% done (\"{1}\")", new Object[] { progress, world.getName() });
timestamp = System.currentTimeMillis(); timestamp = System.currentTimeMillis();
} }
@ -164,11 +164,11 @@ public class BlockStorage {
} }
} finally { } finally {
long time = (System.currentTimeMillis() - start); long time = (System.currentTimeMillis() - start);
Slimefun.getLogger().log(Level.INFO, "Loading Blocks... 100% (FINISHED - {0}ms)", time); SlimefunPlugin.logger().log(Level.INFO, "Loading Blocks... 100% (FINISHED - {0}ms)", time);
Slimefun.getLogger().log(Level.INFO, "Loaded a total of {0} Blocks for World \"{1}\"", new Object[] { totalBlocks, world.getName() }); SlimefunPlugin.logger().log(Level.INFO, "Loaded a total of {0} Blocks for World \"{1}\"", new Object[] { totalBlocks, world.getName() });
if (totalBlocks > 0) { if (totalBlocks > 0) {
Slimefun.getLogger().log(Level.INFO, "Avg: {0}ms/Block", NumberUtils.roundDecimalNumber((double) time / (double) totalBlocks)); SlimefunPlugin.logger().log(Level.INFO, "Avg: {0}ms/Block", NumberUtils.roundDecimalNumber((double) time / (double) totalBlocks));
} }
} }
} }
@ -193,7 +193,7 @@ public class BlockStorage {
* error to the console (if enabled). * error to the console (if enabled).
*/ */
if (SlimefunPlugin.getRegistry().logDuplicateBlockEntries()) { if (SlimefunPlugin.getRegistry().logDuplicateBlockEntries()) {
Slimefun.getLogger().log(Level.INFO, "Ignoring duplicate block @ {0}, {1}, {2} ({3} -> {4})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), blockInfo.getString("id"), storage.get(l).getString("id") }); SlimefunPlugin.logger().log(Level.INFO, "Ignoring duplicate block @ {0}, {1}, {2} ({3} -> {4})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), blockInfo.getString("id"), storage.get(l).getString("id") });
} }
return; return;
@ -206,7 +206,7 @@ public class BlockStorage {
} }
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.WARNING, x, () -> "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion());
} }
} }
@ -223,7 +223,7 @@ public class BlockStorage {
SlimefunPlugin.getRegistry().getChunks().put(key, data); SlimefunPlugin.getRegistry().getChunks().put(key, data);
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.WARNING, x, () -> "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion());
} }
} }
} }
@ -245,7 +245,7 @@ public class BlockStorage {
inventories.put(l, new BlockMenu(preset, l, cfg)); inventories.put(l, new BlockMenu(preset, l, cfg));
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while loading this Block Inventory: " + file.getName()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while loading this Block Inventory: " + file.getName());
} }
} }
} }
@ -260,7 +260,7 @@ public class BlockStorage {
SlimefunPlugin.getRegistry().getUniversalInventories().put(preset.getID(), new UniversalBlockMenu(preset, cfg)); SlimefunPlugin.getRegistry().getUniversalInventories().put(preset.getID(), new UniversalBlockMenu(preset, cfg));
} }
} catch (Exception x) { } catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while loading this universal Inventory: " + file.getName()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while loading this universal Inventory: " + file.getName());
} }
} }
} }
@ -291,7 +291,7 @@ public class BlockStorage {
return; return;
} }
Slimefun.getLogger().log(Level.INFO, "Saving block data for world \"{0}\" ({1} change(s) queued)", new Object[] { world.getName(), changes }); SlimefunPlugin.logger().log(Level.INFO, "Saving block data for world \"{0}\" ({1} change(s) queued)", new Object[] { world.getName(), changes });
Map<String, Config> cache = new HashMap<>(blocksCache); Map<String, Config> cache = new HashMap<>(blocksCache);
for (Map.Entry<String, Config> entry : cache.entrySet()) { for (Map.Entry<String, Config> entry : cache.entrySet()) {
@ -305,7 +305,7 @@ public class BlockStorage {
try { try {
Files.delete(file.toPath()); Files.delete(file.toPath());
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.WARNING, e, () -> "Could not delete file \"" + file.getName() + '"'); SlimefunPlugin.logger().log(Level.WARNING, e, () -> "Could not delete file \"" + file.getName() + '"');
} }
} }
} else { } else {
@ -315,7 +315,7 @@ public class BlockStorage {
try { try {
Files.move(tmpFile.toPath(), cfg.getFile().toPath(), StandardCopyOption.ATOMIC_MOVE); Files.move(tmpFile.toPath(), cfg.getFile().toPath(), StandardCopyOption.ATOMIC_MOVE);
} catch (IOException x) { } catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while copying a temporary File for Slimefun " + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "An Error occurred while copying a temporary File for Slimefun " + SlimefunPlugin.getVersion());
} }
} }
} }
@ -431,7 +431,7 @@ public class BlockStorage {
try { try {
return new BlockInfoConfig(parseJSON(json)); return new BlockInfoConfig(parseJSON(json));
} catch (Exception x) { } catch (Exception x) {
Logger logger = Slimefun.getLogger(); Logger logger = SlimefunPlugin.logger();
logger.log(Level.WARNING, x.getClass().getName()); logger.log(Level.WARNING, x.getClass().getName());
logger.log(Level.WARNING, "Failed to parse BlockInfo for Block @ {0}, {1}, {2}", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ() }); logger.log(Level.WARNING, "Failed to parse BlockInfo for Block @ {0}, {1}, {2}", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ() });
logger.log(Level.WARNING, json); logger.log(Level.WARNING, json);
@ -457,7 +457,7 @@ public class BlockStorage {
writer.endObject(); writer.endObject();
return string.toString(); return string.toString();
} catch (IOException x) { } catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, "An error occurred while serializing BlockInfo", x); SlimefunPlugin.logger().log(Level.SEVERE, "An error occurred while serializing BlockInfo", x);
return null; return null;
} }
} }
@ -508,7 +508,7 @@ public class BlockStorage {
BlockStorage storage = getStorage(l.getWorld()); BlockStorage storage = getStorage(l.getWorld());
if (storage == null) { if (storage == null) {
Slimefun.getLogger().warning("Could not set Block info for non-registered World '" + l.getWorld().getName() + "'. Is some plugin trying to store data in a fake world?"); SlimefunPlugin.logger().warning("Could not set Block info for non-registered World '" + l.getWorld().getName() + "'. Is some plugin trying to store data in a fake world?");
return; return;
} }
@ -817,7 +817,7 @@ public class BlockStorage {
return cfg; return cfg;
} catch (Exception e) { } catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion()); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion());
return emptyBlockData; return emptyBlockData;
} }
} }

View File

@ -25,9 +25,15 @@ public final class Slimefun {
private Slimefun() {} private Slimefun() {}
/**
* This returns the {@link Logger} for Slimefun.
*
* @deprecated Use {@link SlimefunPlugin#logger()} instead
*/
@Deprecated
@Nonnull @Nonnull
public static Logger getLogger() { public static Logger getLogger() {
return SlimefunPlugin.instance().getLogger(); return SlimefunPlugin.logger();
} }
/** /**

View File

@ -10,7 +10,7 @@ import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.cscorelib2.config.Config;
import me.mrCookieSlime.Slimefun.api.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
// This class will be deprecated, relocated and rewritten in a future version. // This class will be deprecated, relocated and rewritten in a future version.
public class BlockMenu extends DirtyChestMenu { public class BlockMenu extends DirtyChestMenu {
@ -118,7 +118,7 @@ public class BlockMenu extends DirtyChestMenu {
try { try {
Files.delete(file.toPath()); Files.delete(file.toPath());
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.WARNING, e, () -> "Could not delete file \"" + file.getName() + '"'); SlimefunPlugin.logger().log(Level.WARNING, e, () -> "Could not delete file \"" + file.getName() + '"');
} }
} }
} }