TF-EssentialsX/Essentials/src/main/java/com/earth2me/essentials/commands/Commandnuke.java

58 lines
1.9 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
2015-04-15 04:06:16 +00:00
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
2015-04-15 04:06:16 +00:00
import static com.earth2me.essentials.I18n.tl;
public class Commandnuke extends EssentialsCommand {
public Commandnuke() {
super("nuke");
}
2015-04-15 04:06:16 +00:00
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException {
2020-10-03 17:46:05 +00:00
final Collection<Player> targets;
2015-04-15 04:06:16 +00:00
if (args.length > 0) {
2015-06-03 20:11:56 +00:00
targets = new ArrayList<>();
for (int i = 0; i < args.length; ++i) {
targets.add(getPlayer(server, sender, args, i).getBase());
2015-04-15 04:06:16 +00:00
}
} else {
targets = ess.getOnlinePlayers();
}
ess.getTNTListener().enable();
2020-10-03 17:46:05 +00:00
for (final Player player : targets) {
2015-04-15 04:06:16 +00:00
if (player == null) {
continue;
}
player.sendMessage(tl("nuke"));
final Location loc = player.getLocation();
final World world = loc.getWorld();
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);
2015-04-15 04:06:16 +00:00
}
}
}
}
@Override
2020-10-03 17:46:05 +00:00
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}