2022-03-25 05:45:55 +00:00
|
|
|
package dev.plex.listener.impl;
|
|
|
|
|
|
|
|
import dev.plex.listener.PlexListener;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2022-04-07 04:02:45 +00:00
|
|
|
|
2022-04-07 14:59:04 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-04-07 04:02:45 +00:00
|
|
|
import net.kyori.adventure.sound.Sound;
|
2022-04-07 14:59:04 +00:00
|
|
|
import org.bukkit.Location;
|
2022-04-07 04:02:45 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Particle;
|
2022-04-07 14:59:04 +00:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2022-03-25 05:45:55 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
|
|
|
|
public class BlockListener extends PlexListener
|
|
|
|
{
|
|
|
|
public List<String> blockedPlayers = new ArrayList<>();
|
|
|
|
|
2022-04-07 04:02:45 +00:00
|
|
|
private static final List<Material> blockedBlocks = new ArrayList<>();
|
|
|
|
|
|
|
|
private static List<String> cachedBlockedBlocksConfig = null;
|
|
|
|
|
2022-03-25 05:45:55 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event)
|
|
|
|
{
|
2022-04-07 04:02:45 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:59:04 +00:00
|
|
|
Block block = event.getBlock();
|
2022-04-07 04:02:45 +00:00
|
|
|
|
2022-04-07 14:59:04 +00:00
|
|
|
if (blockedPlayers.contains(event.getPlayer().getName()))
|
2022-03-25 05:45:55 +00:00
|
|
|
{
|
2022-04-07 14:59:04 +00:00
|
|
|
event.setCancelled(true);
|
2022-03-25 05:45:55 +00:00
|
|
|
}
|
2022-04-07 04:02:45 +00:00
|
|
|
|
2022-04-07 14:59:04 +00:00
|
|
|
if (blockedBlocks.contains(block.getType()))
|
2022-03-25 05:45:55 +00:00
|
|
|
{
|
2022-04-07 14:59:04 +00:00
|
|
|
block.setType(Material.CAKE);
|
|
|
|
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5,0.5,0.5));
|
2022-03-25 05:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onBlockBreak(BlockBreakEvent event)
|
|
|
|
{
|
|
|
|
if (blockedPlayers.size() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (blockedPlayers.contains(event.getPlayer().getName()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|