diff --git a/README.md b/README.md index 5d187c0..9af8f05 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ implementation("com.cjburkey.claimchunk:claimchunk:0.0.25-FIX1") Building -------- [![Automatic Build](https://img.shields.io/github/actions/workflow/status/cjburkey01/ClaimChunk/gradle.yml?branch=main&style=for-the-badge)](https://claimchunk.cjburkey.com/server/Downloads.html#snapshot-downloads) -[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.0.25-FIX1&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/main.zip) +[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.0.26-SNAPSHOT1&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/main.zip) If you want to obtain a version of the plugin that isn't available yet (like a snapshot), you can do so by asking on the Discord or building it yourself. Here's how to build it yourself: diff --git a/build.gradle.kts b/build.gradle.kts index 28e7243..f02bbab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ object DepData { const val JAVA_VERSION = 17 const val LIVE_VERSION = "0.0.25-FIX1" - const val THIS_VERSION = "0.0.25-FIX1" + const val THIS_VERSION = "0.0.26-SNAPSHOT1" const val PLUGIN_NAME = "ClaimChunk" const val ARCHIVES_BASE_NAME = "claimchunk" const val MAIN_CLASS = "com.cjburkey.claimchunk.ClaimChunk" diff --git a/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java b/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java index d3dbf5d..431217c 100644 --- a/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java +++ b/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java @@ -129,6 +129,8 @@ public final class ClaimChunk extends JavaPlugin implements IClaimChunkPlugin { public ClaimChunk() {} + // -- Plugin load/unload -- // + @Override public void onLoad() { // Assign the global instance to this instance of the plugin @@ -204,17 +206,11 @@ public void onEnable() { // Enable each layer modularLayerHandler.onEnable(); - // Check for an update - initUpdateChecker(); - // Start data collection with bStats initAnonymousData(); // Initialize the data handler and exit if it fails - if (!initDataHandler()) { - disable(); - return; - } + initDataHandler(); // Initialize all the variables // cmd = new CommandHandler(this); @@ -258,12 +254,9 @@ public void onEnable() { try { dataHandler.load(); } catch (Exception e) { - Utils.err("Failed to load the data handler, ClaimChunk will be disabled!"); + Utils.err("Failed to load the data handler, server will now crash!"); Utils.err("Here is the error for reference:"); - //noinspection CallToPrintStackTrace - e.printStackTrace(); - disable(); - return; + throw new RuntimeException("Failed to load data handler data!", e); } Utils.debug("Loaded chunk data."); @@ -300,8 +293,13 @@ public void onEnable() { // Done! Utils.log("Initialization complete."); + + // Check for an update + initUpdateChecker(); } + // -- Initialization support -- // + private void initLayers() { // TODO: INSERT LAYERS FOR EACH OF THE MODULAR ELEMENTS OF THE PLUGIN. @@ -321,38 +319,6 @@ private void initUpdateChecker() { } } - private void doUpdateCheck() { - try { - // Get the latest online plugin version - availableVersion = UpdateChecker.getLatestRelease("cjburkey01", "ClaimChunk"); - - // Make sure the latest available version is valid - if (availableVersion == null) { - Utils.err("Failed to get latest version of ClaimChunk from GitHub"); - return; - } - - if (availableVersion.isNewerThan(version)) { - // If the latest available version is newer than the current plugin version, the - // server - // should be updated - updateAvailable = true; - Utils.log( - "An update for ClaimChunk is available! Your version: %s | Latest version:" - + " %s", - version, availableVersion); - } else { - Utils.log( - "You are using the latest version of ClaimChunk: %s (Online: %s)", - version, availableVersion); - } - } catch (Exception e) { - Utils.err("Failed to check for update"); - //noinspection CallToPrintStackTrace - e.printStackTrace(); - } - } - private void initAnonymousData() { // bStats: https://bstats.org/ if (config.getAnonymousMetrics()) { @@ -372,26 +338,9 @@ private void initAnonymousData() { } } - @SuppressWarnings("CommentedOutCode") - private boolean initDataHandler() { + @SuppressWarnings("ResultOfMethodCallIgnored") + private void initDataHandler() { // Initialize the data handler if another plugin hasn't substituted one already - /*if (dataHandler == null) { - // The ternary operator is great - // But it's ugly sometimes - // Yuck! - dataHandler = - (config.getUseDatabase()) - ? ((config.getGroupRequests()) - ? new BulkMySQLDataHandler<>( - this, - this::createJsonDataHandler, - JsonDataHandler::deleteFiles) - : new MySQLDataHandler<>( - this, - this::createJsonDataHandler, - JsonDataHandler::deleteFiles)) - : createJsonDataHandler(); - }*/ if (dataHandler == null) { File dataFolder = new File(getDataFolder(), "/data"); dataFolder.mkdirs(); @@ -403,6 +352,9 @@ private boolean initDataHandler() { IClaimChunkDataHandler oldDataHandler = null; if (!sqliteFile.exists() && (oldUseDb || (oldClaimedFile.exists() && oldPlayerFile.exists()))) { + // The ternary operator is great + // But it's ugly sometimes + // Yuck! oldDataHandler = oldUseDb ? ((config.getGroupRequests()) @@ -441,20 +393,16 @@ private boolean initDataHandler() { try { // Initialize the data handler if (!dataHandler.getHasInit()) dataHandler.init(); - return true; } catch (Exception e) { Utils.err( "Failed to initialize data storage system \"%s\", disabling ClaimChunk.", dataHandler.getClass().getName()); - //noinspection CallToPrintStackTrace - e.printStackTrace(); Utils.err("CLAIMCHUNK WILL NOT WORK WITHOUT A VALID DATA STORAGE SYSTEM!"); Utils.err( "Please double check your config and make sure it's set to the correct data" + " information to ensure ClaimChunk can operate normally"); + throw new RuntimeException("Failed to initialize ClaimChunk data handler!", e); } - System.exit(-1); - return false; } private void initMessages() { @@ -550,7 +498,7 @@ private void handleAutoUnclaim() { } private void setupConfig() { - File configFile = new File(getDataFolder() + File.separator + "config.yml"); + File configFile = new File(getDataFolder(), "/config.yml"); if (!configFile.exists()) { getConfig().options().copyDefaults(true); } else { @@ -604,6 +552,38 @@ private void setupNewCommands() { mainHandler = new MainHandler(this); } + private void doUpdateCheck() { + try { + // Get the latest online plugin version + availableVersion = UpdateChecker.getLatestRelease("cjburkey01", "ClaimChunk"); + + // Make sure the latest available version is valid + if (availableVersion == null) { + Utils.err("Failed to get latest version of ClaimChunk from GitHub"); + return; + } + + if (availableVersion.isNewerThan(version)) { + // If the latest available version is newer than the current plugin version, the + // server + // should be updated + updateAvailable = true; + Utils.log( + "An update for ClaimChunk is available! Your version: %s | Latest version:" + + " %s", + version, availableVersion); + } else { + Utils.log( + "You are using the latest version of ClaimChunk: %s (Online: %s)", + version, availableVersion); + } + } catch (Exception e) { + Utils.err("Failed to check for update"); + //noinspection CallToPrintStackTrace + e.printStackTrace(); + } + } + private void scheduleDataSaver() { // From minutes, calculate after how long in ticks to save data. int saveTimeTicks = config.getSaveDataIntervalInMinutes() * 1200;