2022-03-25 05:45:55 +00:00
|
|
|
package dev.plex.listener.impl;
|
|
|
|
|
|
|
|
import dev.plex.listener.PlexListener;
|
2022-04-13 02:22:17 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-03-25 05:45:55 +00:00
|
|
|
import java.util.ArrayList;
|
2022-04-07 18:05:15 +00:00
|
|
|
import java.util.Arrays;
|
2022-03-25 05:45:55 +00:00
|
|
|
import java.util.List;
|
2022-04-07 18:05:15 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-04-07 04:02:45 +00:00
|
|
|
import org.bukkit.Material;
|
2022-04-07 14:59:04 +00:00
|
|
|
import org.bukkit.block.Block;
|
2022-04-07 18:05:15 +00:00
|
|
|
import org.bukkit.block.Sign;
|
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-04-07 18:05:15 +00:00
|
|
|
private static final List<Material> SIGNS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SIGN")).toList();
|
|
|
|
|
2022-03-25 05:45:55 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event)
|
|
|
|
{
|
2022-04-09 05:08:03 +00:00
|
|
|
List<String> blockedBlocksConfig = plugin.config.getStringList("blocked_blocks");
|
2022-04-07 04:02:45 +00:00
|
|
|
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-04-07 18:37:33 +00:00
|
|
|
return;
|
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);
|
2022-04-09 05:08:03 +00:00
|
|
|
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5));
|
2022-03-25 05:45:55 +00:00
|
|
|
}
|
2022-04-07 18:05:15 +00:00
|
|
|
|
2022-04-09 05:08:03 +00:00
|
|
|
if (SIGNS.contains(block.getType()))
|
2022-04-07 18:05:15 +00:00
|
|
|
{
|
2022-04-09 05:08:03 +00:00
|
|
|
Sign sign = (Sign)block.getState();
|
2022-04-07 18:05:15 +00:00
|
|
|
boolean anythingChanged = false;
|
|
|
|
for (int i = 0; i < sign.lines().size(); i++)
|
|
|
|
{
|
|
|
|
Component line = sign.line(i);
|
2022-04-09 05:08:03 +00:00
|
|
|
if (line.clickEvent() != null)
|
2022-04-07 18:05:15 +00:00
|
|
|
{
|
|
|
|
anythingChanged = true;
|
|
|
|
sign.line(i, line.clickEvent(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (anythingChanged)
|
|
|
|
{
|
|
|
|
sign.update(true);
|
|
|
|
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);
|
2022-04-07 18:37:33 +00:00
|
|
|
return;
|
2022-03-25 05:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|