add block blocker

in the future, this will be it's own module or something
This commit is contained in:
ayunami2000 2022-04-07 00:02:45 -04:00
parent 00d00eb4e5
commit 199832e020
2 changed files with 42 additions and 0 deletions

View File

@ -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<String> blockedPlayers = new ArrayList<>();
private static final List<Material> blockedBlocks = new ArrayList<>();
private static List<String> cachedBlockedBlocksConfig = null;
@EventHandler(priority = EventPriority.LOW)
public void onBlockPlace(BlockPlaceEvent event)
{
List<String> 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);

View File

@ -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"