Skip to content

Commit

Permalink
Start working on changing flags
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Aug 8, 2024
1 parent 13e67df commit 1f3376c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/cjburkey/claimchunk/Utils.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.cjburkey.claimchunk;

import com.cjburkey.claimchunk.placeholder.ClaimChunkPlaceholders;

import lombok.Getter;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -196,9 +193,20 @@ public static Map<String, Boolean> getAllFalsePermissionsMap() {
return permissionsMap;
}

// Should prevent the old enum values from mucking everything up :)
public static @Nullable Material materialFromString(String input) {
// First, try to match based on the new enum values
Material matchedEnum = Material.matchMaterial(input);
if (matchedEnum != null) {
return matchedEnum;
}

// Otherwise, try the legacy as a fallback
return Material.matchMaterial(input, true);
}

// -- JAVA UTIL -- //

// TODO: TEST????
public static <K, V> HashMap<K, V> deepCloneMap(HashMap<K, V> map, Function<V, V> cloneFunc) {
return map.entrySet().stream()
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public void fromCCConfig(@NotNull CCConfig config) {
config.getStrList("_.preventAdjacent").stream()
.map(
blockType -> {
Material material = Material.getMaterial(blockType);
Material material = Utils.materialFromString(blockType);
if (material == null) {
Utils.warn(
"Material type \"%s\" not found when loading from"
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/flags/PermFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cjburkey.claimchunk.flags;

public class PermFlag {

// TODO: INCLUDE BLOCK/ENTITY PROTECTIONS

}
14 changes: 14 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/flags/PermFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cjburkey.claimchunk.flags;

import java.io.File;
import java.util.HashMap;

public class PermFlags {

private final File flagsFile;
private final HashMap<String, PermFlag> flagMap = new HashMap<>();

public PermFlags(File flagsFile) {
this.flagsFile = flagsFile;
}
}
58 changes: 58 additions & 0 deletions src/main/resources/defaultFlags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# List of flags that players can customize within their claims.

permissionFlags:
breakBlocks:
# Blocks
- for: BLOCKS # BLOCKS or ENTITIES
type: BREAK # For blocks, can be BREAK, PLACE, INTERACT, or EXPLODE
# If no `include` or `exclude` (cannot be used together, btw)
# is present, the default is to include all blocks/entities.
# If `include` is present, only the provided entities/entity
# classes will be included.
# The opposite is true of `exclude`, which includes all
# default blocks/items and excludes the provided ones.
placeBlocks:
- for: BLOCKS
type: PLACE
interactBlocks:
- for: BLOCKS
type: INTERACT
exclude: ['@REDSTONE', '@DOORS', '@BLOCK_CONTAINERS'] # Handle these separately
redstone:
- for: BLOCKS
type: INTERACT
include: ['@REDSTONE']
doors:
- for: BLOCKS
type: INTERACT
include: ['@DOORS']

# Entities
damageEntities:
- for: ENTITIES
type: DAMAGE
interactEntities:
- for: ENTITIES
type: INTERACT
exclude: ['@VEHICLES']
vehicles:
- for: ENTITIES
type: INTERACT
include: ['@VEHICLES']

# Can also handle both types with one flag
containers:
- for: BLOCKS
type: INTERACT
include: ['@BLOCK_CONTAINERS']
- for: ENTITIES
type: INTERACT
include: ['@VEHICLE_CONTAINERS']

# Explosions
explodeHurt:
- for: ENTITIES
type: EXPLODE
explodeDamage:
- for: BLOCKS
type: EXPLODE

0 comments on commit 1f3376c

Please sign in to comment.