migrate to per material config

This commit is contained in:
Jakob Schulz
2026-05-19 18:37:57 +02:00
parent 706f6ed743
commit e9c766dbbb
3 changed files with 20 additions and 37 deletions
@@ -411,7 +411,7 @@ public final class GameModeConfig<M, W> {
} }
@ToString @ToString
public static final class ArenaConfig { public static final class ArenaConfig<M, W> {
public final boolean loaded; public final boolean loaded;
@@ -461,18 +461,11 @@ public final class GameModeConfig<M, W> {
public final boolean DisableSnowMelt; public final boolean DisableSnowMelt;
/** /**
* Disable ice forming * Disable the forming of certain blocks
* *
* @implSpec {@code false} by default * @implSpec {@code empty} by default
*/ */
public final boolean DisableIceForm; public final Set<M> BlockedFormedBlocks;
/**
* Disable block generators such as cobblestone, stone, obsidian and basalt
*
* @implSpec {@code false} by default
*/
public final boolean DisableBlockGenerators;
/** /**
* Allow leaving the arena area as spectator * Allow leaving the arena area as spectator
@@ -495,7 +488,7 @@ public final class GameModeConfig<M, W> {
*/ */
public final boolean NoFloor; public final boolean NoFloor;
private ArenaConfig(YMLWrapper loader, SchematicConfig.SizeConfig Size, List<Integer> EnterStages) { private ArenaConfig(YMLWrapper<M,W> loader, SchematicConfig.SizeConfig Size, List<Integer> EnterStages) {
loaded = loader.canLoad(); loaded = loader.canLoad();
WaterDepth = loader.getInt("WaterDepth", 0); WaterDepth = loader.getInt("WaterDepth", 0);
WaterDamage = loader.getBoolean("WaterDamage", true); WaterDamage = loader.getBoolean("WaterDamage", true);
@@ -504,8 +497,11 @@ public final class GameModeConfig<M, W> {
BorderFromSchematic = loader.getInt("BorderFromSchematic", 21); BorderFromSchematic = loader.getInt("BorderFromSchematic", 21);
GroundWalkable = loader.getBoolean("GroundWalkable", true); GroundWalkable = loader.getBoolean("GroundWalkable", true);
DisableSnowMelt = loader.getBoolean("DisableSnowMelt", false); DisableSnowMelt = loader.getBoolean("DisableSnowMelt", false);
DisableIceForm = loader.getBoolean("DisableIceForm", false); Set<M> blockedFormedBlocks = new HashSet<>(loader.getMaterialList("BlockedFormedBlocks"));
DisableBlockGenerators = loader.getBoolean("DisableBlockGenerators", false); if (loader.getBoolean("DisableIceForm", false)) {
blockedFormedBlocks.add(loader.materialMapper.apply("ICE"));
}
BlockedFormedBlocks = Collections.unmodifiableSet(blockedFormedBlocks);
Leaveable = loader.getBoolean("Leaveable", false); Leaveable = loader.getBoolean("Leaveable", false);
AllowMissiles = loader.getBoolean("AllowMissiles", !EnterStages.isEmpty()); AllowMissiles = loader.getBoolean("AllowMissiles", !EnterStages.isEmpty());
NoFloor = loader.getBoolean("NoFloor", false); NoFloor = loader.getBoolean("NoFloor", false);
+7 -4
View File
@@ -48,10 +48,13 @@ Arena:
GroundWalkable: true # defaults to true if missing GroundWalkable: true # defaults to true if missing
# Disable snow and ice melting # Disable snow and ice melting
DisableSnowMelt: false # defaults to false if missing DisableSnowMelt: false # defaults to false if missing
# Disable ice forming # Disabled blocks from forming
DisableIceForm: false # defaults to false if missing BlockedFormedBlocks:
# Disable cobblestone, stone, obsidian and basalt generators # For Cobble Generators
DisableBlockGenerators: false # defaults to false if missing # - COBBLESTONE
# - BASALT
# - STONE
# - OBSIDIAN
# Allow leaving the arena area as spectator # Allow leaving the arena area as spectator
Leaveable: false # defaults to false if missing Leaveable: false # defaults to false if missing
# Allow missiles to fly to the enemy and not stop at the schem border. # Allow missiles to fly to the enemy and not stop at the schem border.
@@ -27,25 +27,13 @@ import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFormEvent;
import java.util.EnumSet;
import java.util.Set;
@Linked @Linked
public class BlockFormListener implements Listener { public class BlockFormListener implements Listener {
private static final Set<Material> GENERATOR_BLOCKS = EnumSet.of(
Material.COBBLESTONE,
Material.STONE,
Material.OBSIDIAN,
Material.BASALT
);
public BlockFormListener() { public BlockFormListener() {
boolean enabled = Config.GameModeConfig.Arena.DisableIceForm boolean enabled = !Config.GameModeConfig.Arena.BlockedFormedBlocks.isEmpty();
|| Config.GameModeConfig.Arena.DisableBlockGenerators; new StateDependentListener(enabled, FightState.All, this);
new StateDependentListener(enabled,
Config.GameModeConfig.Arena.DisableIceForm ? FightState.All : FightState.Running,
this);
} }
@EventHandler @EventHandler
@@ -53,11 +41,7 @@ public class BlockFormListener implements Listener {
if (!Config.ArenaRegion.inRegion(event.getBlock())) return; if (!Config.ArenaRegion.inRegion(event.getBlock())) return;
Material material = event.getNewState().getType(); Material material = event.getNewState().getType();
if (Config.GameModeConfig.Arena.DisableIceForm && material == Material.ICE) { if (Config.GameModeConfig.Arena.BlockedFormedBlocks.contains(material)) {
event.setCancelled(true);
} else if (Config.GameModeConfig.Arena.DisableBlockGenerators
&& FightState.infight()
&& GENERATOR_BLOCKS.contains(material)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }