Skip to content

Commit

Permalink
feat: moved destroy-placed-blocks-by-explosion to game config container
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Feb 25, 2024
1 parent 54b4763 commit d3ac493
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ public interface GameConfigurationContainer extends ConfigurationContainer {

ConfigurationKey<Boolean> KICK_PLAYERS_UPON_FINAL_DEATH_ENABLED = ConfigurationKey.of(Boolean.class, "kick-players-upon-final-death", "enabled");
ConfigurationKey<Integer> KICK_PLAYERS_UPON_FINAL_DEATH_DELAY = ConfigurationKey.of(Integer.class, "kick-players-upon-final-death", "delay");

ConfigurationKey<Boolean> DESTROY_PLACED_BLOCKS_BY_EXPLOSION_ENABLED = ConfigurationKey.of(Boolean.class, "destroy-placed-blocks-by-explosion", "enabled");
ConfigurationListKey<String> DESTROY_PLACED_BLOCKS_BY_EXPLOSION_BLACKLIST = ConfigurationListKey.of(String.class, "destroy-placed-blocks-by-explosion", "blacklist"); // Block predicates (block state, #tag or type[*])
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public class GameConfigurationContainerImpl extends ConfigurationContainerImpl i
register(STATISTICS_SCORES_RECORD, "statistics", "scores", "record");
register(KICK_PLAYERS_UPON_FINAL_DEATH_ENABLED, "kick-players-upon-final-death", "enabled");
register(KICK_PLAYERS_UPON_FINAL_DEATH_ENABLED, "kick-players-upon-final-death", "delay");
register(DESTROY_PLACED_BLOCKS_BY_EXPLOSION_ENABLED, "destroy-placed-blocks-by-explosion", "enabled");
register(DESTROY_PLACED_BLOCKS_BY_EXPLOSION_BLACKLIST, "destroy-placed-blocks-by-explosion", "blacklist");
}

protected void migrateOld(ConfigurationNode configurationNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,25 @@ public void load() {
.key("disable-hunger").defValue(false)
.key("automatic-coloring-in-shop").defValue(true)
.key("sell-max-64-per-click-in-shop").defValue(true)
.key("destroy-placed-blocks-by-explosion-except")
.remapWhen(node -> !node.empty() && !node.isList())
.remap(node -> {
if (!node.empty() && !node.isList()) {
var str = node.getString();
try {
var data = str == null ? List.of() : List.of(str);
node.set(data);
} catch(SerializationException ex) {
ex.printStackTrace();
}
}
})
.defValue(List::of)
.key("destroy-placed-blocks-by-explosion").defValue(true)
.key("destroy-placed-blocks-by-explosion").moveIfAbsolute(n -> !n.virtual() && !n.isMap(), "destroy-placed-blocks-by-explosion", "enabled")
.section("destroy-placed-blocks-by-explosion")
.key("enabled").defValue(true)
.key("blacklist")
.migrateOldAbsoluteKey("destroy-placed-blocks-by-explosion-except")
.remapWhen(node -> !node.empty() && !node.isList())
.remap(node -> {
if (!node.empty() && !node.isList()) {
var str = node.getString();
try {
var data = str == null ? List.of() : List.of(str);
node.set(data);
} catch(SerializationException ex) {
ex.printStackTrace();
}
}
})
.defValue(List::of)
.back()
.key("holograms-above-bed").migrateOld("holo-above-bed").defValue(true)
.key("allow-spectator-join").defValue(false)
.section("disable-server-message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.spongepowered.configurate.ConfigurationNode;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Service
Expand Down Expand Up @@ -147,13 +148,13 @@ public void onExplode(BlockExplodeEvent event) {
}

public void onExplode(Location location, Collection<BlockPlacement> blockList, org.screamingsandals.lib.event.Cancellable cancellable, boolean originatedInArena) {
final var explosionExceptionTypeName = MainConfig.getInstance().node("destroy-placed-blocks-by-explosion-except").childrenList().stream().map(ConfigurationNode::getString).toArray();
final var destroyPlacedBlocksByExplosion = MainConfig.getInstance().node("destroy-placed-blocks-by-explosion").getBoolean(true);
final var breakableExplosions = MainConfig.getInstance().node("breakable", "explosions").getBoolean(true);

for (var game : GameManagerImpl.getInstance().getGames()) {
if (ArenaUtils.isInArea(location, game.getPos1(), game.getPos2())) {
if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
final var destroyPlacedBlocksByExplosion = game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.DESTROY_PLACED_BLOCKS_BY_EXPLOSION_ENABLED, true);
final var explosionExceptionTypeName = game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.DESTROY_PLACED_BLOCKS_BY_EXPLOSION_BLACKLIST, List.of()).toArray();
blockList.removeIf(block -> {
if (!game.isBlockAddedDuringGame(block.location())) {
if (game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.TARGET_BLOCK_ALLOW_DESTROYING_WITH_EXPLOSIONS, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,43 +81,46 @@ config:
game-start-items:
enabled: true
items:
- WOODEN_SWORD
- LEATHER_HELMET
- LEATHER_CHESTPLATE
- LEATHER_LEGGINGS
- LEATHER_BOOTS
- wooden_sword
- leather_helmet
- leather_chestplate
- leather_leggings
- leather_boots
destroy-placed-blocks-by-explosion:
enabled: true
blacklist:
- glass


# TODO: custom destroy-placed-blocks-by-explosion-except > GLASS
# TODO: breakable blocks (GRASS, LONG_GRASS, SNOW)
# TODO: just add every missing configuration

default-spawner-types-included: false
custom-spawner-types:
emerald:
spread: 0.1
material: EMERALD
material: emerald
translate: resource_emerald
interval: 60
color: GREEN
name: Emerald
diamond:
spread: 0.1
material: DIAMOND
material: diamond
translate: resource_diamond
interval: 30
color: BLUE
name: Diamond
iron:
spread: 0.1
material: IRON_INGOT
material: iron_ingot
translate: resource_iron
interval: 2 # interval is currently still int btw, default value in SBA: 2.5
color: WHITE
name: Iron
gold:
spread: 0.1
material: GOLD_INGOT
material: gold_ingot
translate: resource_gold
interval: 8
color: GOLD
Expand Down

0 comments on commit d3ac493

Please sign in to comment.