Skip to content

Commit

Permalink
Work on flag permission checking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Aug 20, 2024
1 parent afad146 commit e404227
Show file tree
Hide file tree
Showing 58 changed files with 527 additions and 2,699 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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.26&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 = 21

const val LIVE_VERSION = "0.0.25-FIX3"
const val THIS_VERSION = "0.0.26"
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.goldmensch.commanddispatcher;
package claimchunk.dependency.de.goldmensch.commanddispatcher;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.goldmensch.commanddispatcher;
package claimchunk.dependency.de.goldmensch.commanddispatcher;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.goldmensch.commanddispatcher;
package claimchunk.dependency.de.goldmensch.commanddispatcher;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.goldmensch.commanddispatcher.annotations;
package claimchunk.dependency.de.goldmensch.commanddispatcher.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.goldmensch.commanddispatcher.command;

import de.goldmensch.commanddispatcher.ArraySets;
import de.goldmensch.commanddispatcher.ArrayUtil;
import de.goldmensch.commanddispatcher.Executor;
import de.goldmensch.commanddispatcher.annotations.Description;
import de.goldmensch.commanddispatcher.exceptions.CommandNotValidException;
import de.goldmensch.commanddispatcher.subcommand.SmartSubCommand;
package claimchunk.dependency.de.goldmensch.commanddispatcher.command;

import claimchunk.dependency.de.goldmensch.commanddispatcher.ArraySets;
import claimchunk.dependency.de.goldmensch.commanddispatcher.ArrayUtil;
import claimchunk.dependency.de.goldmensch.commanddispatcher.Executor;
import claimchunk.dependency.de.goldmensch.commanddispatcher.annotations.Description;
import claimchunk.dependency.de.goldmensch.commanddispatcher.exceptions.CommandNotValidException;
import claimchunk.dependency.de.goldmensch.commanddispatcher.subcommand.SmartSubCommand;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.goldmensch.commanddispatcher.exceptions;
package claimchunk.dependency.de.goldmensch.commanddispatcher.exceptions;

import de.goldmensch.commanddispatcher.subcommand.SmartSubCommand;
import claimchunk.dependency.de.goldmensch.commanddispatcher.subcommand.SmartSubCommand;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.goldmensch.commanddispatcher.subcommand;
package claimchunk.dependency.de.goldmensch.commanddispatcher.subcommand;

import de.goldmensch.commanddispatcher.Executor;
import claimchunk.dependency.de.goldmensch.commanddispatcher.Executor;

import lombok.Getter;

Expand Down
59 changes: 5 additions & 54 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.cjburkey.claimchunk.cmd.*;
import com.cjburkey.claimchunk.config.ClaimChunkWorldProfileHandler;
import com.cjburkey.claimchunk.config.ccconfig.*;
import com.cjburkey.claimchunk.data.DataConvert;
import com.cjburkey.claimchunk.data.newdata.*;
import com.cjburkey.claimchunk.data.sqlite.SqLiteDataHandler;
import com.cjburkey.claimchunk.event.*;
Expand Down Expand Up @@ -38,7 +37,6 @@

import java.io.*;
import java.lang.reflect.Field;
import java.nio.file.Files;

// TODO: Split this plugin up into services that users can use
// Services:
Expand Down Expand Up @@ -227,7 +225,7 @@ public void onLoad() {
+ " else is probably wrong!");
}

permFlags = new CCPermFlags();
permFlags = new CCPermFlags(this);
try {
permFlags.load(new File(getDataFolder(), "flags.yml"), this, "flags.yml");
Utils.log("Loaded permission flags from flags.yml");
Expand Down Expand Up @@ -441,45 +439,7 @@ private boolean initDataHandler() {
File dataFolder = new File(getDataFolder(), "/data");
if (dataFolder.mkdirs()) Utils.debug("Create ClaimChunk data folder");
File sqliteFile = new File(dataFolder, "/claimAndPlayerData.sqlite3");
File oldClaimedFile = new File(dataFolder, "/claimedChunks.json");
File oldPlayerFile = new File(dataFolder, "/playerData.json");
boolean oldUseDb = config.getUseDatabase();

IClaimChunkDataHandler oldDataHandler = null;
if (!sqliteFile.exists()
&& (oldUseDb || (oldClaimedFile.exists() && oldPlayerFile.exists()))) {
oldDataHandler =
oldUseDb
? ((config.getGroupRequests())
? new BulkMySQLDataHandler<>(
this, this::createJsonDataHandler, ignored -> {})
: new MySQLDataHandler<>(
this, this::createJsonDataHandler, ignored -> {}))
: createJsonDataHandler();
}

dataHandler = new SqLiteDataHandler(sqliteFile);

if (oldDataHandler != null) {
try {
DataConvert.copyConvert(oldDataHandler, dataHandler);
oldDataHandler.exit();

if (oldClaimedFile.exists()) {
Files.move(
oldClaimedFile.toPath(),
new File(dataFolder, "/OLD_claimedChunks.json").toPath());
}
if (oldPlayerFile.exists()) {
Files.move(
oldPlayerFile.toPath(),
new File(dataFolder, "/OLD_playerData.json").toPath());
}
} catch (Exception e) {
throw new RuntimeException(
"Failed to initialize previous data handler to convert old data!", e);
}
}
}

Utils.debug("Using data handler \"%s\"", dataHandler.getClass().getName());
Expand Down Expand Up @@ -547,15 +507,6 @@ private void initEcon() {
Utils.log("Economy not enabled.");
}

@SuppressWarnings("unused")
private JsonDataHandler createJsonDataHandler() {
// Create the basic JSON data handler
return new JsonDataHandler(
this,
new File(getDataFolder(), "/data/claimedChunks.json"),
new File(getDataFolder(), "/data/playerData.json"));
}

private void handleAutoUnclaim() {
int length = config.getAutomaticUnclaimSeconds();
// Less than 1 will disable the check
Expand All @@ -571,13 +522,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 @@ -588,7 +539,7 @@ private void handleAutoUnclaim() {

Utils.log(
"Unclaimed all chunks of player \"%s\" (%s)",
player.lastIgn, player.player);
player.lastIgn(), player.player());
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public class ClaimChunkConfig {

/* Data */

@Getter private boolean keepJsonBackups;
@Getter private int saveDataIntervalInMinutes;
@Getter private int deleteOldBackupsAfterMinutes;
@Getter private int minBackupIntervalInMinutes;

/* Database */

Expand Down Expand Up @@ -151,10 +148,7 @@ public void reload() {
chunkOutlineHeightRadius = getInt("chunkOutline", "heightRadius");
chunkOutlineUseNewEffect = getBool("chunkOutline", "useNewEffect");

keepJsonBackups = getBool("data", "keepJsonBackups");
saveDataIntervalInMinutes = getInt("data", "saveDataIntervalInMinutes");
deleteOldBackupsAfterMinutes = getInt("data", "deleteOldBackupsAfterMinutes");
minBackupIntervalInMinutes = getInt("data", "minBackupIntervalInMinutes");

useDatabase = getBool("database", "useDatabase");
groupRequests = getBool("database", "groupRequests");
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -212,6 +213,18 @@ public static Map<String, Boolean> getAllFalsePermissionsMap() {
return Material.matchMaterial(input, true);
}

public static @Nullable EntityType entityFromString(String input) {
try {
String mc = "minecraft:";
if (input.toLowerCase().startsWith(mc)) {
input = input.substring(mc.length());
}
return EntityType.valueOf(input.toUpperCase());
} catch (Exception ignored) {
}
return null;
}

// -- JAVA UTIL -- //

public static <K, V> HashMap<K, V> deepCloneMap(HashMap<K, V> map, Function<V, V> cloneFunc) {
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/cjburkey/claimchunk/access/CCFlags.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.cjburkey.claimchunk.access;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Set;

public final class CCFlags {

// Generics...gotta love 'em, but feel free to hate them too.
// Methods named such that they may align with record getters :}
public interface IFlagData<TypeEnum extends Enum<TypeEnum>> {
@NotNull
Expand All @@ -30,7 +28,24 @@ public enum EntityFlagType {
EXPLODE,
}

public record FlagData(@Nullable List<String> include, @Nullable List<String> exclude) {}
public enum ProtectWhen {
ENABLED,
DISABLED;

public boolean ifEnabled() {
return this == ENABLED;
}

public boolean doesProtect(boolean isFlagEnabled) {
if (ifEnabled()) {
return isFlagEnabled;
}
return !isFlagEnabled;
}
}

public record FlagData(
ProtectWhen protectWhen, @NotNull Set<String> include, @NotNull Set<String> exclude) {}

public record BlockFlagData(@NotNull BlockFlagType flagType, @NotNull FlagData flagData)
implements IFlagData<BlockFlagType> {}
Expand Down
Loading

1 comment on commit e404227

@cjburkey01
Copy link
Owner Author

@cjburkey01 cjburkey01 commented on e404227 Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BE WARNED!

THIS COMMIT REMOVES PRE-0.0.25 DATA HANDLERS!

FROM NOW ON

Make sure to start your server with 0.0.25 at least once to convert your data to the new format!

Please sign in to comment.