From 199832e020cecc1954a5afcd1fceec5372980297 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Thu, 7 Apr 2022 00:02:45 -0400 Subject: [PATCH] add block blocker in the future, this will be it's own module or something --- .../dev/plex/listener/impl/BlockListener.java | 36 +++++++++++++++++++ src/main/resources/config.yml | 6 ++++ 2 files changed, 42 insertions(+) diff --git a/src/main/java/dev/plex/listener/impl/BlockListener.java b/src/main/java/dev/plex/listener/impl/BlockListener.java index 9bec3ea..95fa716 100644 --- a/src/main/java/dev/plex/listener/impl/BlockListener.java +++ b/src/main/java/dev/plex/listener/impl/BlockListener.java @@ -3,6 +3,10 @@ package dev.plex.listener.impl; import dev.plex.listener.PlexListener; import java.util.ArrayList; import java.util.List; + +import net.kyori.adventure.sound.Sound; +import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; @@ -12,13 +16,45 @@ public class BlockListener extends PlexListener { public List blockedPlayers = new ArrayList<>(); + private static final List blockedBlocks = new ArrayList<>(); + + private static List cachedBlockedBlocksConfig = null; + @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent event) { + List blockedBlocksConfig = plugin.config.getStringList("blockedBlocks"); + if (blockedBlocksConfig != cachedBlockedBlocksConfig) + { + blockedBlocks.clear(); + cachedBlockedBlocksConfig = blockedBlocksConfig; + for (String block : blockedBlocksConfig) + { + try + { + blockedBlocks.add(Material.valueOf(block.toUpperCase())); + } + catch (IllegalArgumentException e) + { + // + } + } + } + + if (blockedBlocks.contains(event.getBlock().getType())) + { + event.getBlock().setType(Material.COBWEB); + Particle.CLOUD.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(5).spawn(); + Particle.FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(3).spawn(); + Particle.SOUL_FIRE_FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).offset(0.5,0.5,0.5).extra(0).count(2).spawn(); + event.getPlayer().playSound(Sound.sound(org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH.key(), Sound.Source.BLOCK, 0.5f, 0.5f)); + } + if (blockedPlayers.size() == 0) { return; } + if (blockedPlayers.contains(event.getPlayer().getName())) { event.setCancelled(true); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8a0b567..9324c18 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -154,6 +154,12 @@ autowipe: # Should we allow drops from players? allowdrops: true +# What blocks should be blocked? +blockedBlocks: + - "SPAWNER" + - "STRUCTURE_BLOCK" + - "JIGSAW" + worlds: flatlands: name: "Flatlands"