From 2189616a9e971b390d10f31275e9e7a7975f0fa2 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Thu, 4 Jul 2024 21:43:19 +0200 Subject: [PATCH] fix dangerous block blocker not having list of dangerous blocks --- .../preventstabby/config/ConfigCache.java | 19 +++++++++++++++++++ .../listeners/EnvironmentalListener.java | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java index b34dfc3..19b3225 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java +++ b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java @@ -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; @@ -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 combatBlockedCommands = new HashSet<>(); + private final Set dangerousBlocks = new HashSet<>(); private final FileConfiguration config; @@ -124,6 +126,19 @@ public class ConfigCache { 2.5, List.of("Distance from the player where placing dangerous blocks will be disallowed") ); + List 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); + } + } @@ -175,6 +190,10 @@ public class ConfigCache { return Collections.unmodifiableSet(combatBlockedCommands); } + public Set getDangerousBlocks() { + return Collections.unmodifiableSet(dangerousBlocks); + } + private String getString(String path, @NotNull String def) { return getString(path, def, null); } diff --git a/src/main/java/me/youhavetrouble/preventstabby/listeners/EnvironmentalListener.java b/src/main/java/me/youhavetrouble/preventstabby/listeners/EnvironmentalListener.java index 29f7973..b1b98a9 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/listeners/EnvironmentalListener.java +++ b/src/main/java/me/youhavetrouble/preventstabby/listeners/EnvironmentalListener.java @@ -78,13 +78,14 @@ public class EnvironmentalListener implements Listener { } @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);