diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 11:43:25 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 11:43:25 +0000 |
commit | 797dde94e17247d16965e6d5570a8d64b6f7d858 (patch) | |
tree | 44ac925fd08afbe4a3738f42c83a408448408070 | |
parent | b83bb1faa376047a0c92d1fcb78e286eac0f6538 (diff) | |
download | Essentials-797dde94e17247d16965e6d5570a8d64b6f7d858.tar Essentials-797dde94e17247d16965e6d5570a8d64b6f7d858.tar.gz Essentials-797dde94e17247d16965e6d5570a8d64b6f7d858.tar.lz Essentials-797dde94e17247d16965e6d5570a8d64b6f7d858.tar.xz Essentials-797dde94e17247d16965e6d5570a8d64b6f7d858.zip |
May death rain upon them
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1561 e251c2fe-e539-e718-e476-b85c1f46cddb
5 files changed, 145 insertions, 1 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 7531c03f5..cbd8d66b2 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -30,7 +30,6 @@ import com.earth2me.essentials.register.payment.Methods; import java.math.BigInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; @@ -50,6 +49,7 @@ public class Essentials extends JavaPlugin implements IEssentials private EssentialsBlockListener blockListener; private EssentialsEntityListener entityListener; private JailPlayerListener jailPlayerListener; + private TNTExplodeListener tntListener; private static Essentials instance = null; private Spawn spawn; private Jail jail; @@ -187,6 +187,9 @@ public class Essentials extends JavaPlugin implements IEssentials getServer().createWorld(settings.getNetherName(), World.Environment.NETHER); } + tntListener = new TNTExplodeListener(this); + pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this); + timer = new EssentialsTimer(this); getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50); if (enableErrorLogging) @@ -730,6 +733,11 @@ public class Essentials extends JavaPlugin implements IEssentials return this.getScheduler().scheduleSyncDelayedTask(this, run); } + public int scheduleSyncDelayedTask(final Runnable run, final long delay) + { + return this.getScheduler().scheduleSyncDelayedTask(this, run, delay); + } + public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period) { return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period); @@ -744,4 +752,9 @@ public class Essentials extends JavaPlugin implements IEssentials { return bannedIps; } + + public TNTExplodeListener getTNTListener() + { + return tntListener; + } } diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index 8cc905355..ef099860b 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -60,9 +60,13 @@ public interface IEssentials int scheduleSyncDelayedTask(Runnable run); + int scheduleSyncDelayedTask(Runnable run, long delay); + int scheduleSyncRepeatingTask(final Runnable run, long delay, long period); List<String> getBans(); List<String> getBannedIps(); + + TNTExplodeListener getTNTListener(); } diff --git a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java new file mode 100644 index 000000000..0b7c136c7 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java @@ -0,0 +1,82 @@ +package com.earth2me.essentials; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import net.minecraft.server.ChunkPosition; +import net.minecraft.server.Packet60Explosion; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + + +public class TNTExplodeListener extends EntityListener implements Runnable +{ + private final IEssentials ess; + private boolean enabled = false; + private int timer = -1; + + public TNTExplodeListener(IEssentials ess) + { + this.ess = ess; + } + + public void enable() + { + if (!enabled) + { + enabled = true; + timer = ess.scheduleSyncDelayedTask(this, 1000); + return; + } + if (timer != -1) { + ess.getScheduler().cancelTask(timer); + timer = ess.scheduleSyncDelayedTask(this, 1000); + } + } + + @Override + public void onEntityExplode(final EntityExplodeEvent event) + { + if (!enabled) + { + return; + } + if (event.getEntity() instanceof LivingEntity) + { + return; + } + final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); + final Player[] players = ess.getServer().getOnlinePlayers(); + final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length); + final Location loc = event.getLocation(); + for (Player player : players) + { + if (player.getWorld().equals(loc.getWorld())) + { + blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ())); + } + } + for (Block block : event.blockList()) + { + final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); + if (!blocksUnderPlayers.contains(cp)) + { + set.add(cp); + } + } + ((CraftServer)ess.getServer()).getHandle().a(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set)); + event.setCancelled(true); + } + + public void run() + { + enabled = false; + } +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java new file mode 100644 index 000000000..bd736d056 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java @@ -0,0 +1,41 @@ +package com.earth2me.essentials.commands; + +import net.minecraft.server.EntityTNTPrimed; +import net.minecraft.server.World; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.entity.Player; + + +public class Commandnuke extends EssentialsCommand +{ + public Commandnuke() + { + super("nuke"); + } + + @Override + protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) + { + Location loc; + World world; + server.broadcastMessage("May death rain upon them"); + ess.getTNTListener().enable(); + for (Player player : server.getOnlinePlayers()) + { + loc = player.getLocation(); + world = ((CraftWorld)loc.getWorld()).getHandle(); + for (int x = -10; x <= 10; x += 5) + { + for (int z = -10; z <= 10; z += 5) + { + final EntityTNTPrimed tnt = new EntityTNTPrimed(world, loc.getBlockX() + x, 120, loc.getBlockZ() + z); + world.addEntity(tnt); + world.makeSound(tnt, "random.fuse", 1.0F, 1.0F); + } + } + } + } +} diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index b255f4c82..6c26d8cb2 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -175,6 +175,10 @@ commands: description: Change your nickname or that of another player.
usage: /<command> <player> [nickname|off]
aliases: [enick]
+ nuke:
+ description: May death rain upon them.
+ usage: /<command>
+ aliases: [enuke]
pay:
description: Pays another player from your balance
usage: /<command> [player] [amount]
|