Skip to content

Commit

Permalink
Fix CommandModule
Browse files Browse the repository at this point in the history
  • Loading branch information
getplusm committed Dec 29, 2023
1 parent c193415 commit 25164ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DungeonStage> stagesCache;

public CommandModule(@NotNull Dungeon dungeon, @NotNull String id) {
super(dungeon, id, false);
super(dungeon, id, true);
}

@Override
protected Predicate<Boolean> 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<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25164ec

Please sign in to comment.