Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start working on 0.0.26 #298

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-FIX3")
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-FIX3&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
8 changes: 7 additions & 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-FIX3"
const val THIS_VERSION = "0.0.25-FIX3"
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 Expand Up @@ -116,6 +116,10 @@ tasks {
relocate("org.osgi", "claimchunk.dependency.org.osgi")
}

register<Delete>("cleanTests") {
delete(fileTree(mainDir).include("*.tmp.sqlite3"))
}

test {
useJUnitPlatform()

Expand All @@ -124,6 +128,8 @@ tasks {
"junit.jupiter.extensions.autodetection.enabled" to "true",
"junit.jupiter.testinstance.lifecycle.default" to "per_class"
)

finalizedBy("cleanTests")
}

clean {
Expand Down
136 changes: 60 additions & 76 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.cjburkey.claimchunk.data.newdata.*;
import com.cjburkey.claimchunk.data.sqlite.SqLiteDataHandler;
import com.cjburkey.claimchunk.event.*;
import com.cjburkey.claimchunk.gui.CCGuiHandler;
import com.cjburkey.claimchunk.i18n.V2JsonMessages;
import com.cjburkey.claimchunk.layer.PlaceholderInitLayer;
import com.cjburkey.claimchunk.layer.PrereqsInitLayer;
Expand Down Expand Up @@ -106,8 +107,9 @@ public final class ClaimChunk extends JavaPlugin implements IClaimChunkPlugin {
// The main /chunk command
@Getter CCBukkitCommand mainCommand;
// The main handler (may not always be here, please don't rely on this)
@Getter private MainHandler mainHandler;
@Getter private CoreActionHandler mainHandler;
@Getter private ChunkOutlineHandler chunkOutlineHandler;
@Getter private CCGuiHandler guiHandler;

// Config conversion storage
private FromPre0023 fromPre0023;
Expand All @@ -129,6 +131,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 +208,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 +256,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 +295,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 +321,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 +340,9 @@ private void initAnonymousData() {
}
}

@SuppressWarnings("CommentedOutCode")
private boolean initDataHandler() {
@SuppressWarnings({"ResultOfMethodCallIgnored", "deprecation"})
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 +354,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 +395,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 @@ -502,7 +452,7 @@ private void initEcon() {
Utils.log("Economy not enabled.");
}

@SuppressWarnings("unused")
@SuppressWarnings("deprecation")
private JsonDataHandler createJsonDataHandler() {
// Create the basic JSON data handler
return new JsonDataHandler(
Expand All @@ -526,13 +476,13 @@ private void handleAutoUnclaim() {

for (SimplePlayerData player : playerHandler.getJoinedPlayers()) {
// If the player has joined since time was recorded (that's 1s)
boolean playerJoinedSinceTimeRecordUpdate = player.lastOnlineTime > 1000;
boolean playerJoinedSinceTimeRecordUpdate = player.lastOnlineTime() > 1000;
// If the player hasn't been online recently enough
boolean playerBeenOfflineTooLong = player.lastOnlineTime < (time - (1000L * length));
boolean playerBeenOfflineTooLong = player.lastOnlineTime() < (time - (1000L * length));

if (playerJoinedSinceTimeRecordUpdate && playerBeenOfflineTooLong) {
// Get a list of all the player's chunks
ChunkPos[] claimedChunks = chunkHandler.getClaimedChunks(player.player);
ChunkPos[] claimedChunks = chunkHandler.getClaimedChunks(player.player());

if (claimedChunks.length > 0) {
// Unclaim all of the player's chunks
Expand All @@ -543,14 +493,14 @@ private void handleAutoUnclaim() {

Utils.log(
"Unclaimed all chunks of player \"%s\" (%s)",
player.lastIgn, player.player);
player.lastIgn(), player.player());
}
}
}
}

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 @@ -585,10 +535,13 @@ private void setupConfig() {
}

private void setupEvents() {
guiHandler = new CCGuiHandler();

// Register all the event handlers
getServer().getPluginManager().registerEvents(new PlayerConnectionHandler(this), this);
getServer().getPluginManager().registerEvents(new PlayerMovementHandler(this), this);
getServer().getPluginManager().registerEvents(new WorldProfileEventHandler(this), this);
getServer().getPluginManager().registerEvents(guiHandler, this);
}

private void setupNewCommands() {
Expand All @@ -601,7 +554,38 @@ private void setupNewCommands() {

// An archaic class controlling a shit-ton of shit. Needs to be cleaned up during the API
// change :/
mainHandler = new MainHandler(this);
mainHandler = new CoreActionHandler(this);
}

private void doUpdateCheck() {
try {
// Get the latest online plugin version
availableVersion = UpdateChecker.getLatestRelease();

// 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 version 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() {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ClaimChunkConfig {
@Getter private int chunkOutlineSpawnPerSec;
@Getter private int chunkOutlineParticlesPerSpawn;
@Getter private int chunkOutlineHeightRadius;
@Getter private boolean chunkOutlineNewEffect;

/* Data */

Expand Down Expand Up @@ -74,6 +75,22 @@ public class ClaimChunkConfig {
@Getter private boolean anonymousMetrics;
@Getter private boolean debugSpam;

/* GUI */
@Getter private String guiMenuBackButtonItem;
@Getter private String guiMainMenuCurrentChunkItem;
@Getter private String guiMainMenuChunkMapItem;
@Getter private String guiMainMenuPermFlagsItem;
@Getter private boolean guiMapMenuAllowClaimOtherChunks;
@Getter private String guiMapMenuUnclaimedItem;
@Getter private String guiMapMenuSelfClaimedItem;
@Getter private String guiMapMenuOtherClaimedItem;
@Getter private String guiMapMenuCenterUnclaimedItem;
@Getter private String guiMapMenuCenterSelfClaimedItem;
@Getter private String guiMapMenuCenterOtherClaimedItem;
@Getter private String guiPermSelectMenuItem;
@Getter private String guiPermModifyAllowItem;
@Getter private String guiPermModifyDenyItem;

/* Titles */

@Getter private boolean useTitlesInsteadOfChat;
Expand Down Expand Up @@ -134,6 +151,7 @@ public void reload() {
chunkOutlineSpawnPerSec = getInt("chunkOutline", "spawnsPerSecond");
chunkOutlineParticlesPerSpawn = getInt("chunkOutline", "particlesPerSpawn");
chunkOutlineHeightRadius = getInt("chunkOutline", "heightRadius");
chunkOutlineNewEffect = getBool("chunkOutline", "useNewEffect");

keepJsonBackups = getBool("data", "keepJsonBackups");
saveDataIntervalInMinutes = getInt("data", "saveDataIntervalInMinutes");
Expand All @@ -160,6 +178,21 @@ public void reload() {
anonymousMetrics = getBool("log", "anonymousMetrics");
debugSpam = getBool("log", "debugSpam");

guiMenuBackButtonItem = getString("gui", "menuBackButtonItem");
guiMainMenuCurrentChunkItem = getString("gui", "mainMenuCurrentChunkItem");
guiMainMenuChunkMapItem = getString("gui", "mainMenuChunkMapItem");
guiMainMenuPermFlagsItem = getString("gui", "mainMenuPermFlagsItem");
guiMapMenuAllowClaimOtherChunks = getBool("gui", "mapMenuAllowClaimOtherChunks");
guiMapMenuUnclaimedItem = getString("gui", "mapMenuUnclaimedItem");
guiMapMenuSelfClaimedItem = getString("gui", "mapMenuSelfClaimedItem");
guiMapMenuOtherClaimedItem = getString("gui", "mapMenuOtherClaimedItem");
guiMapMenuCenterUnclaimedItem = getString("gui", "mapMenuCenterUnclaimedItem");
guiMapMenuCenterSelfClaimedItem = getString("gui", "mapMenuCenterSelfClaimedItem");
guiMapMenuCenterOtherClaimedItem = getString("gui", "mapMenuCenterOtherClaimedItem");
guiPermSelectMenuItem = getString("gui", "permSelectMenuItem");
guiPermModifyAllowItem = getString("gui", "permModifyAllowItem");
guiPermModifyDenyItem = getString("gui", "permModifyDenyItem");

useTitlesInsteadOfChat = getBool("titles", "useTitlesInsteadOfChat");
useActionBar = getBool("titles", "useActionBar");
titleFadeInTime = getInt("titles", "titleFadeInTime");
Expand Down
Loading
Loading