From 25164ec8706b7897bf267e3a230b9166975b973b Mon Sep 17 00:00:00 2001 From: plazmer <48393153+getplusm@users.noreply.github.com> Date: Sat, 30 Dec 2023 04:24:45 +0500 Subject: [PATCH] Fix CommandModule --- .../dungeon/modules/AbstractModule.java | 5 +-- .../dungeon/modules/impl/CommandModule.java | 34 +++++++++++++++---- .../dungeon/modules/impl/SpawnModule.java | 15 +++++--- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java index 5abc9cc..df55b95 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java @@ -91,10 +91,7 @@ public void update() { this.dungeon().cancel(false); // TODO add cancelled all modules to cancel method } } else if (!canActivate && isActive()) { - if (!deactivate()) { - return; - } - this.plugin().debug("Deactivate dungeon '" + this.dungeon().getId() + "' module '" + this.getId() + "'"); + deactivate(); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java index 17c9640..dfdc17c 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java @@ -4,38 +4,58 @@ import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; -import java.util.ArrayList; -import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; +import java.util.Set; import java.util.function.Predicate; public class CommandModule extends AbstractModule { + private Set stagesCache; + public CommandModule(@NotNull Dungeon dungeon, @NotNull String id) { - super(dungeon, id, false); + super(dungeon, id, true); } @Override protected Predicate onLoad() { + this.stagesCache = new LinkedHashSet<>(); return aBoolean -> true; } @Override protected void onShutdown() { - + if (this.stagesCache != null) { + this.stagesCache.clear(); + this.stagesCache = null; + } } @Override public boolean onActivate() { - CompletableFuture.runAsync(() -> this.dungeon().getCommandsSettings().getCommands(this.dungeon().getStage()).forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command))); return true; } + @Override + public void update() { + List commands = this.dungeon().getCommandsSettings().getCommands(this.dungeon().getStage()); + if (!commands.isEmpty() && !this.stagesCache.contains(this.dungeon().getStage())) { + if (this.stagesCache == null) + this.stagesCache = new LinkedHashSet<>(); + stagesCache.add(this.dungeon().getStage()); + + commands.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); + } + super.update(); + } + @Override public boolean onDeactivate() { + if (this.stagesCache != null) { + this.stagesCache.clear(); + } return true; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java index 7c6c9f6..b649b88 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java @@ -10,6 +10,7 @@ import t.me.p1azmer.engine.utils.random.Rnd; import t.me.p1azmer.plugin.dungeons.api.events.DungeonDeleteEvent; import t.me.p1azmer.plugin.dungeons.api.events.DungeonSpawnEvent; +import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; import t.me.p1azmer.plugin.dungeons.generator.RangeInfo; @@ -91,22 +92,28 @@ public boolean onActivate() { Block block = result.getBlock(); Biome biome = block.getBiome(); + RegionHandler handler = plugin().getRegionHandler(); + if (handler != null){ + if (!handler.isValidLocation(result)){ + return false; + } + } if (rangeInfo.isBiomesAsBlack()) { if (rangeInfo.getBiomes().contains(biome)) { - this.error("Biomes not contains biome " + biome.name()); + this.debug("Biomes not contains biome " + biome.name()); return false; } } else if (!rangeInfo.getBiomes().contains(biome)) { - this.error("Biomes not contains biome " + biome.name()); + this.debug("Biomes not contains biome " + biome.name()); return false; } if (rangeInfo.isMaterialsAsBlack()) { if (rangeInfo.getMaterials().contains(block.getType())) { - this.error("Materials contains block " + block.getType().name()); + this.debug("Materials contains block " + block.getType().name()); return false; } } else if (!rangeInfo.getMaterials().contains(block.getType())) { - this.error("Materials not contains block " + block.getType().name()); + this.debug("Materials not contains block " + block.getType().name()); return false; } return this.spawn(result);