Skip to content

Commit

Permalink
Start working on 0.0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 26, 2024
1 parent 4a04c1b commit 4183563
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
118 changes: 49 additions & 69 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");

Expand Down Expand Up @@ -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.

Expand All @@ -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()) {
Expand All @@ -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();
Expand All @@ -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())
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4183563

Please sign in to comment.