mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Use metadata for tnt from /nuke (#5222)
Fixes https://github.com/EssentialsX/Essentials/issues/5219
This commit is contained in:
parent
b3238605cc
commit
312d1699a8
@ -144,7 +144,7 @@ import static com.earth2me.essentials.I18n.tl;
|
||||
public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private static final Logger BUKKIT_LOGGER = Logger.getLogger("Essentials");
|
||||
private static Logger LOGGER = null;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener();
|
||||
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
|
||||
private transient ISettings settings;
|
||||
private transient Jails jails;
|
||||
@ -1193,11 +1193,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TNTExplodeListener getTNTListener() {
|
||||
return tntListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsHandler getPermissionsHandler() {
|
||||
return permissionsHandler;
|
||||
|
@ -110,8 +110,6 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
|
||||
|
||||
TNTExplodeListener getTNTListener();
|
||||
|
||||
PermissionsHandler getPermissionsHandler();
|
||||
|
||||
AlternativeCommandsHandler getAlternativeCommandsHandler();
|
||||
|
@ -1,51 +1,22 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import com.earth2me.essentials.commands.Commandnuke;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class TNTExplodeListener implements Listener, Runnable {
|
||||
private final transient IEssentials ess;
|
||||
private transient boolean enabled = false;
|
||||
private transient int timer = -1;
|
||||
|
||||
public TNTExplodeListener(final IEssentials ess) {
|
||||
super();
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
if (!enabled) {
|
||||
enabled = true;
|
||||
timer = ess.scheduleSyncDelayedTask(this, 200);
|
||||
return;
|
||||
}
|
||||
if (timer != -1) {
|
||||
ess.getScheduler().cancelTask(timer);
|
||||
timer = ess.scheduleSyncDelayedTask(this, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public class TNTExplodeListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onEntityExplode(final EntityExplodeEvent event) {
|
||||
if (!enabled) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed)) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
return;
|
||||
}
|
||||
if (event.blockList().size() < 1) {
|
||||
if (!event.getEntity().hasMetadata(Commandnuke.NUKE_META_KEY)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -15,6 +16,9 @@ import java.util.List;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandnuke extends EssentialsCommand {
|
||||
|
||||
public static final String NUKE_META_KEY = "ess_tnt_proj";
|
||||
|
||||
public Commandnuke() {
|
||||
super("nuke");
|
||||
}
|
||||
@ -30,7 +34,6 @@ public class Commandnuke extends EssentialsCommand {
|
||||
} else {
|
||||
targets = ess.getOnlinePlayers();
|
||||
}
|
||||
ess.getTNTListener().enable();
|
||||
for (final Player player : targets) {
|
||||
if (player == null) {
|
||||
continue;
|
||||
@ -38,9 +41,12 @@ public class Commandnuke extends EssentialsCommand {
|
||||
player.sendMessage(tl("nuke"));
|
||||
final Location loc = player.getLocation();
|
||||
final World world = loc.getWorld();
|
||||
if (world != null) {
|
||||
for (int x = -10; x <= 10; x += 5) {
|
||||
for (int z = -10; z <= 10; z += 5) {
|
||||
world.spawn(new Location(world, loc.getBlockX() + x, world.getHighestBlockYAt(loc) + 64, loc.getBlockZ() + z), TNTPrimed.class);
|
||||
final TNTPrimed entity = world.spawn(new Location(world, loc.getBlockX() + x, world.getHighestBlockYAt(loc) + 64, loc.getBlockZ() + z), TNTPrimed.class);
|
||||
entity.setMetadata(NUKE_META_KEY, new FixedMetadataValue(ess, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user