mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-09-12 13:19:33 +00:00
81 lines
2.1 KiB
Java
81 lines
2.1 KiB
Java
package com.earth2me.essentials.signs;
|
|
|
|
import net.ess3.api.IEssentials;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
|
|
public class SignEntityListener implements Listener
|
|
{
|
|
private final transient IEssentials ess;
|
|
|
|
public SignEntityListener(final IEssentials ess)
|
|
{
|
|
this.ess = ess;
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
public void onEntityExplode(final EntityExplodeEvent event)
|
|
{
|
|
if (ess.getSettings().areSignsDisabled())
|
|
{
|
|
event.getHandlers().unregister(this);
|
|
return;
|
|
}
|
|
|
|
for (Block block : event.blockList())
|
|
{
|
|
if (((block.getTypeId() == Material.WALL_SIGN.getId()
|
|
|| block.getTypeId() == Material.SIGN_POST.getId())
|
|
&& EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block)))
|
|
|| EssentialsSign.checkIfBlockBreaksSigns(block))
|
|
{
|
|
event.setCancelled(true);
|
|
return;
|
|
}
|
|
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
|
{
|
|
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType()))
|
|
{
|
|
event.setCancelled(!sign.onBlockExplode(block, ess));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
public void onEntityChangeBlock(final EntityChangeBlockEvent event)
|
|
{
|
|
if (ess.getSettings().areSignsDisabled())
|
|
{
|
|
event.getHandlers().unregister(this);
|
|
return;
|
|
}
|
|
|
|
final Block block = event.getBlock();
|
|
if (((block.getTypeId() == Material.WALL_SIGN.getId()
|
|
|| block.getTypeId() == Material.SIGN_POST.getId())
|
|
&& EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block)))
|
|
|| EssentialsSign.checkIfBlockBreaksSigns(block))
|
|
{
|
|
event.setCancelled(true);
|
|
return;
|
|
}
|
|
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
|
{
|
|
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
|
&& !sign.onBlockBreak(block, ess))
|
|
{
|
|
event.setCancelled(true);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|