2011-06-02 11:43:25 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2013-07-13 15:14:39 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-06-02 11:43:25 +00:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2012-01-20 04:20:37 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-06-02 11:43:25 +00:00
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
public class TNTExplodeListener implements Listener, Runnable
|
2011-06-02 11:43:25 +00:00
|
|
|
{
|
2011-11-22 02:02:08 +00:00
|
|
|
private final transient IEssentials ess;
|
|
|
|
private transient boolean enabled = false;
|
|
|
|
private transient int timer = -1;
|
2011-06-02 11:43:25 +00:00
|
|
|
|
2011-11-22 02:02:08 +00:00
|
|
|
public TNTExplodeListener(final IEssentials ess)
|
2011-06-02 11:43:25 +00:00
|
|
|
{
|
2011-11-22 02:02:08 +00:00
|
|
|
super();
|
2011-06-02 11:43:25 +00:00
|
|
|
this.ess = ess;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void enable()
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
enabled = true;
|
2012-11-04 02:18:51 +00:00
|
|
|
timer = ess.scheduleSyncDelayedTask(this, 200);
|
2011-06-02 11:43:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
if (timer != -1)
|
|
|
|
{
|
2011-06-02 11:43:25 +00:00
|
|
|
ess.getScheduler().cancelTask(timer);
|
2012-11-04 02:18:51 +00:00
|
|
|
timer = ess.scheduleSyncDelayedTask(this, 200);
|
2011-06-02 11:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
2011-06-02 11:43:25 +00:00
|
|
|
public void onEntityExplode(final EntityExplodeEvent event)
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.getEntity() instanceof LivingEntity)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-03-15 06:42:58 +00:00
|
|
|
if (event.blockList().size() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-06-02 11:43:25 +00:00
|
|
|
event.setCancelled(true);
|
2012-03-15 06:42:58 +00:00
|
|
|
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
2011-06-02 11:43:25 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-02 11:43:25 +00:00
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
}
|