diff --git a/core/src/main/java/eu/mhsl/craftattack/spawn/core/util/IteratorUtil.java b/core/src/main/java/eu/mhsl/craftattack/spawn/core/util/IteratorUtil.java index b8b974d..54478e2 100644 --- a/core/src/main/java/eu/mhsl/craftattack/spawn/core/util/IteratorUtil.java +++ b/core/src/main/java/eu/mhsl/craftattack/spawn/core/util/IteratorUtil.java @@ -31,12 +31,8 @@ public class IteratorUtil { rules.forEach((gameRule, value) -> IteratorUtil.worlds(world -> world.setGameRule(gameRule, value ^ inverse))); } - public static void setIntGameRules(Map, Integer> rules) { - rules.forEach((gameRule, value) -> IteratorUtil.worlds(world -> world.setGameRule(gameRule, value))); - } - public static void times(int times, Runnable callback) { - IntStream.range(0, times).forEach(value -> callback.run()); + IntStream.range(0, times).forEach(_ -> callback.run()); } public static void iterateListInGlobal(int sectionStart, List list, BiConsumer callback) { diff --git a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/tooling/projectStart/ProjectStart.java b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/tooling/projectStart/ProjectStart.java index 1f4d0a5..2484b8d 100644 --- a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/tooling/projectStart/ProjectStart.java +++ b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/tooling/projectStart/ProjectStart.java @@ -26,10 +26,8 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Map; import java.util.Objects; -import static java.util.Map.entry; import static org.bukkit.Sound.MUSIC_DISC_LAVA_CHICKEN; public class ProjectStart extends Appliance { @@ -57,22 +55,23 @@ public class ProjectStart extends Appliance { ) ); - private final Map, Boolean> gameRulesAfterStart = Map.ofEntries( - entry(GameRules.ADVANCE_TIME, true), - entry(GameRules.SPAWN_PHANTOMS, true), - entry(GameRules.RAIDS, true), - entry(GameRules.ENTITY_DROPS, true), - entry(GameRules.SPAWN_PATROLS, true), - entry(GameRules.SPAWN_WANDERING_TRADERS, true), - entry(GameRules.ADVANCE_WEATHER, true), - entry(GameRules.FALL_DAMAGE, true), - entry(GameRules.FIRE_DAMAGE, true) - ); - private final Map, Integer> intGameRulesAfterStart = Map.of( - GameRules.FIRE_SPREAD_RADIUS_AROUND_PLAYER, -1 - ); - private final Map, Integer> intGameRulesBeforeStart = Map.of( - GameRules.FIRE_SPREAD_RADIUS_AROUND_PLAYER, 0 + private record GameRuleSetting(GameRule rule, T before, T after) { + void apply(boolean afterStart) { + IteratorUtil.worlds(world -> world.setGameRule(this.rule, afterStart ? this.after : this.before)); + } + } + + private final List> gameRules = List.of( + new GameRuleSetting<>(GameRules.ADVANCE_TIME, false, true), + new GameRuleSetting<>(GameRules.SPAWN_PHANTOMS, false, true), + new GameRuleSetting<>(GameRules.RAIDS, false, true), + new GameRuleSetting<>(GameRules.ENTITY_DROPS, false, true), + new GameRuleSetting<>(GameRules.SPAWN_PATROLS, false, true), + new GameRuleSetting<>(GameRules.SPAWN_WANDERING_TRADERS, false, true), + new GameRuleSetting<>(GameRules.ADVANCE_WEATHER, false, true), + new GameRuleSetting<>(GameRules.FALL_DAMAGE, false, true), + new GameRuleSetting<>(GameRules.FIRE_DAMAGE, false, true), + new GameRuleSetting<>(GameRules.FIRE_SPREAD_RADIUS_AROUND_PLAYER, 0, -1) ); public ProjectStart() { @@ -81,7 +80,7 @@ public class ProjectStart extends Appliance { this.countdown.addCustomAnnouncement( new Countdown.CustomAnnouncements( counter -> counter == this.startMusicAt, - counter -> this.glassLocation + _ -> this.glassLocation .getWorld() .playSound(this.glassLocation, MUSIC_DISC_LAVA_CHICKEN, SoundCategory.RECORDS, 500f, 1f) ) @@ -126,8 +125,7 @@ public class ProjectStart extends Appliance { this.setEnabled(false); IteratorUtil.worlds(World::getWorldBorder, worldBorder -> worldBorder.setSize(worldBorder.getMaxSize())); - IteratorUtil.worlds(world -> IteratorUtil.setGameRules(this.gameRulesAfterStart, false)); - IteratorUtil.worlds(world -> IteratorUtil.setIntGameRules(this.intGameRulesAfterStart)); + this.gameRules.forEach(setting -> setting.apply(true)); Bukkit.getWorlds().getFirst().setFullTime(0); this.netherFireLocations.forEach(location -> Objects.requireNonNull(this.startWorld).getBlockAt(location).setType(Material.FIRE)); @@ -174,8 +172,7 @@ public class ProjectStart extends Appliance { worldBorder.setDamageAmount(0); }); - IteratorUtil.worlds(world -> world, world -> IteratorUtil.setGameRules(this.gameRulesAfterStart, true)); - IteratorUtil.worlds(world -> world, world -> IteratorUtil.setIntGameRules(this.intGameRulesBeforeStart)); + this.gameRules.forEach(setting -> setting.apply(false)); this.resetAdvancements(); this.blockCycle.reset();