Skip to content

Commit

Permalink
Start working on saving allowed/denied flags
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Aug 17, 2024
1 parent b66c2a1 commit 405fff4
Show file tree
Hide file tree
Showing 13 changed files with 569 additions and 27 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.25-FIX4&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&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.25-FIX4"
const val THIS_VERSION = "0.0.26"
const val PLUGIN_NAME = "ClaimChunk"
const val ARCHIVES_BASE_NAME = "claimchunk"
const val MAIN_CLASS = "com.cjburkey.claimchunk.ClaimChunk"
Expand Down
2 changes: 1 addition & 1 deletion changelogs/0.0.25-FIX2.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ClaimChunk 0.0.25-FIX1
# ClaimChunk 0.0.25-FIX2

Fixes:
* Re-add the `claimchunk_am_trusted` placeholder
Expand Down
2 changes: 1 addition & 1 deletion changelogs/0.0.25-FIX3.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ClaimChunk 0.0.25-FIX1
# ClaimChunk 0.0.25-FIX3

Fixes:
* My stupid update checker
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cjburkey/claimchunk/access/CCFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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<?>> {
public interface IFlagData<TypeEnum extends Enum<TypeEnum>> {
@NotNull
TypeEnum flagType();

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/cjburkey/claimchunk/access/CCPermFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void loadFromConfig(@NotNull YamlConfiguration config) {

// Read each flag name
for (String flagName : flagSection.getKeys(false)) {
if (!flagName.matches("[a-zA-Z0-9_-]+")) {
Utils.err(
"Flag name \"%s\" isn't alphanumeric! Must be a string of A-Z, a-z, 0-9,"
+ " '_', or '-'",
flagName);
continue;
}

// Get the list of maps (see src/resources/defaultFlags.yml for format)
List<Map<?, ?>> flagEntries = flagSection.getMapList(flagName);
if (flagEntries.isEmpty()) {
Expand Down Expand Up @@ -233,7 +241,4 @@ public void loadFromConfig(@NotNull YamlConfiguration config) {
}
return null;
}

// -- CLASSES -- //

}
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,89 @@ default void addPlayer(UUID player, String lastIgn, boolean alerts, int defaultM

// -- ACCESS -- //

/**
* Enable the given permission flag(s) by default in the provided player's chunks.
*
* @param owner Owner of the chunks granting access.
* @param flagNames The name(s) of the flag(s) to grant.
* @since 0.0.26
*/
void grantPermissionFlagsGlobalDefault(UUID owner, String... flagNames);

/**
* Disable the given permission flag(s) by default in the provided player's chunks.
*
* @param owner Owner of the chunks revoking access.
* @param flagNames The name(s) of the flag(s) to revoke.
* @since 0.0.26
*/
void revokePermissionFlagsGlobalDefault(UUID owner, String... flagNames);

/**
* Enable the given permission flag(s) by default in the provided chunk.
*
* @param owner Owner of the chunks granting access.
* @param chunk Position of the chunk to grant access in.
* @param flagNames The name(s) of the flag(s) to grant.
* @since 0.0.26
*/
void grantPermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames);

/**
* Disable the given permission flag(s) by default in the provided chunk.
*
* @param owner Owner of the chunks revoking access.
* @param chunk Position of the chunk to revoke access from.
* @param flagNames The name(s) of the flag(s) to revoke.
* @since 0.0.26
*/
void revokePermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames);

/**
* Enable the given permission flag(s) by default for the provided player in the owner's chunks.
*
* @param owner Owner of the chunks granting access.
* @param accessor Other player having access granted to them.
* @param flagNames The name(s) of the flag(s) to grant.
* @since 0.0.26
*/
void grantPermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames);

/**
* Disable the given permission flag(s) by default for the provided player in the owner's
* chunks.
*
* @param owner Owner of the chunks granting access.
* @param accessor Other player having access revoked from them.
* @param flagNames The name(s) of the flag(s) to revoke.
* @since 0.0.26
*/
void revokePermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames);

/**
* Enable the given permission flag(s) for the provided player in a specific chunk.
*
* @param owner Owner of the chunks granting access.
* @param accessor Other player having access granted to them.
* @param chunk The chunk to grant access to.
* @param flagNames The name(s) of the flag(s) to grant.
* @since 0.0.26
*/
void grantPermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames);

/**
* Disable the given permission flag(s) for the provided player in a specific chunk.
*
* @param owner Owner of the chunks revoking access.
* @param accessor Other player having access revoked from them.
* @param chunk The chunk to take access for.
* @param flagNames The name(s) of the flag(s) to revoke.
* @since 0.0.26
*/
void revokePermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames);

/**
* Gives the provided accessor access (with specific permissions) to the given chunk
*
Expand All @@ -346,6 +429,7 @@ default void addPlayer(UUID player, String lastIgn, boolean alerts, int defaultM
* @param permissions The permissions to be granted to the accessor
* @since 0.0.24
*/
@Deprecated
void givePlayerAccess(ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions);

/**
Expand All @@ -355,6 +439,7 @@ default void addPlayer(UUID player, String lastIgn, boolean alerts, int defaultM
* @param accessor The UUIDs of the player whose access to the chunk should be revoked
* @since 0.0.24
*/
@Deprecated
void takePlayerAccess(ChunkPos chunk, UUID accessor);

/**
Expand All @@ -365,5 +450,6 @@ default void addPlayer(UUID player, String lastIgn, boolean alerts, int defaultM
* @return A map of UUIDs and permissions of all players who can edit this chunk
* @since 0.0.24
*/
@Deprecated
Map<UUID, ChunkPlayerPermissions> getPlayersWithAccess(ChunkPos chunk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,13 @@ public void addPlayers(FullPlayerData[] players) {
}

@Override
@Nullable
public String getPlayerUsername(UUID player) {
public @Nullable String getPlayerUsername(UUID player) {
FullPlayerData ply = joinedPlayers.get(player);
return ply == null ? null : ply.lastIgn;
}

@Override
@Nullable
public UUID getPlayerUUID(String username) {
public @Nullable UUID getPlayerUUID(String username) {
for (FullPlayerData player : joinedPlayers.values()) {
if (player.lastIgn.equals(username)) return player.player;
}
Expand All @@ -191,8 +189,7 @@ public void setPlayerChunkName(UUID player, String name) {
}

@Override
@Nullable
public String getPlayerChunkName(UUID player) {
public @Nullable String getPlayerChunkName(UUID player) {
FullPlayerData ply = joinedPlayers.get(player);
if (ply != null) return ply.chunkName;
return null;
Expand Down Expand Up @@ -277,6 +274,42 @@ public FullPlayerData[] getFullPlayerData() {
return joinedPlayers.values().toArray(new FullPlayerData[0]);
}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsGlobalDefault(UUID owner, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsGlobalDefault(UUID owner, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsChunkDefault(
UUID owner, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsPlayerDefault(
UUID owner, UUID accessor, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {}

private Gson getGson() {
GsonBuilder builder = new GsonBuilder();
return builder.serializeNulls().create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,42 @@ public FullPlayerData[] getFullPlayerData() {
return players.toArray(new FullPlayerData[0]);
}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsGlobalDefault(UUID owner, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsGlobalDefault(UUID owner, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsChunkDefault(
UUID owner, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsPlayerDefault(
UUID owner, UUID accessor, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void grantPermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {}

// Only newer data handlers use this!
@Override
public void revokePermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {}

@Override
public void givePlayerAccess(
ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void load() throws Exception {
for (FullPlayerData player : sqLiteWrapper.getAllPlayers()) {
joinedPlayers.putIfAbsent(player.player, player);
}
for (DataChunk chunk : sqLiteWrapper.getAllChunks()) {
for (DataChunk chunk : SqLiteWrapper.getAllChunksLegacy()) {
claimedChunks.putIfAbsent(chunk.chunk, chunk);
}
}
Expand Down Expand Up @@ -229,6 +229,49 @@ public FullPlayerData[] getFullPlayerData() {
}

@Override
public void grantPermissionFlagsGlobalDefault(UUID owner, String... flagNames) {
sqLiteWrapper.grantPermissionFlagsGlobalDefault(owner, flagNames);
}

@Override
public void revokePermissionFlagsGlobalDefault(UUID owner, String... flagNames) {
sqLiteWrapper.revokePermissionFlagsGlobalDefault(owner, flagNames);
}

@Override
public void grantPermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames) {
sqLiteWrapper.grantPermissionFlagsChunkDefault(owner, chunk, flagNames);
}

@Override
public void revokePermissionFlagsChunkDefault(UUID owner, ChunkPos chunk, String... flagNames) {
sqLiteWrapper.revokePermissionFlagsChunkDefault(owner, chunk, flagNames);
}

@Override
public void grantPermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames) {
sqLiteWrapper.grantPermissionFlagsPlayerDefault(owner, accessor, flagNames);
}

@Override
public void revokePermissionFlagsPlayerDefault(UUID owner, UUID accessor, String... flagNames) {
sqLiteWrapper.revokePermissionFlagsPlayerDefault(owner, accessor, flagNames);
}

@Override
public void grantPermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {
sqLiteWrapper.grantPermissionFlagsPlayerChunk(owner, accessor, chunk, flagNames);
}

@Override
public void revokePermissionFlagsPlayerChunk(
UUID owner, UUID accessor, ChunkPos chunk, String... flagNames) {
sqLiteWrapper.revokePermissionFlagsPlayerChunk(owner, accessor, chunk, flagNames);
}

@Override
@Deprecated
public void givePlayerAccess(
ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions) {
DataChunk chunkData = claimedChunks.get(chunk);
Expand All @@ -239,6 +282,7 @@ public void givePlayerAccess(
}

@Override
@Deprecated
public void takePlayerAccess(ChunkPos chunk, UUID accessor) {
DataChunk chunkData = claimedChunks.get(chunk);
if (chunkData != null) chunkData.playerPermissions.remove(accessor);
Expand Down
Loading

0 comments on commit 405fff4

Please sign in to comment.