Skip to content

Commit

Permalink
fix dangerous block blocker not having list of dangerous blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Jul 4, 2024
1 parent 1484d26 commit 2189616
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.youhavetrouble.preventstabby.config;

import me.youhavetrouble.preventstabby.PreventStabby;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class ConfigCache {
public final double combat_time, login_protection_time, teleport_protection_time, bucket_stopper_radius,
fire_stopper_radius, block_stopper_radius;
private final Set<String> combatBlockedCommands = new HashSet<>();
private final Set<Material> dangerousBlocks = new HashSet<>();

private final FileConfiguration config;

Expand Down Expand Up @@ -124,6 +126,19 @@ public ConfigCache(PreventStabby plugin) {
2.5,
List.of("Distance from the player where placing dangerous blocks will be disallowed")
);
List<String> rawDangerousBlocks = getList(
"settings.environmental.block_stopper.blocks",
List.of("tnt", "magma_block", "cactus", "campfire"),
List.of("List of dangerous blocks that will be blocked when placed near players with pvp off")
);
for (String block : rawDangerousBlocks) {
Material material = Material.matchMaterial(block);
if (material != null) {
dangerousBlocks.add(material);
} else {
plugin.getLogger().warning("Invalid material: " + block);
}
}



Expand Down Expand Up @@ -175,6 +190,10 @@ public Set<String> getCombatBlockedCommands() {
return Collections.unmodifiableSet(combatBlockedCommands);
}

public Set<Material> getDangerousBlocks() {
return Collections.unmodifiableSet(dangerousBlocks);
}

private String getString(String path, @NotNull String def) {
return getString(path, def, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ public void onBlockIgnite(BlockIgniteEvent event) {
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockIgnite(BlockPlaceEvent event) {
public void onDangerousBlockPlace(BlockPlaceEvent event) {
ConfigCache config = plugin.getConfigCache();
if (!config.block_stopper_enabled) return;
Player player = event.getPlayer();
Location location = event.getBlock().getLocation().toCenterLocation();
Target target = Target.getTarget(player);
if (target == null) return;
if (!config.getDangerousBlocks().contains(event.getBlock().getType())) return;
double radius = config.block_stopper_radius;

BoundingBox boundingBox = BoundingBox.of(location.toVector(), radius, radius, radius);
Expand Down

0 comments on commit 2189616

Please sign in to comment.