This plugin spams your caves with torches.
To install this plugin, copy the plugin JAR file to your server's plugins folder.
To run it, type /TORCH ON [DISTANCE] or /TORCH OFF. Be warned, this plugin has a snarky attitude, lol
I currently run a Rainbow server but I want greater functionality than the Rainbow API provides, so I've been learning Spigot. This is one of several silly plugins I've written to that end.
Code (Text):
package FredashaySpigotTorch;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin implements Listener, CommandExecutor {
private static PluginDescriptionFile pdfFile = null;
private static boolean torchOn = false;
private static int torchDistance = 10;
private static Player torchPlayer = null;
private static boolean torchMove = false;
@Override
public void onEnable() {
pdfFile = getDescription();
getServer().getPluginManager().registerEvents(this,this);
clock(2);
}
private void clock(int interval) {
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
onTick();
clock(interval);
}
}, interval);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("torch")) {
if (!(sender instanceof Player)) {
sender.sendMessage("[" + pdfFile.getName() + "] This command can only be issued by a player in the game. ");
return (false);
}
Player player = (Player) sender;
if (player.isOp()) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("on")) {
if (torchOn) {
if (player.getName().equalsIgnoreCase(torchPlayer.getName())) {
player.sendMessage("<Torch> Already on for a radius of " + torchDistance + ". ");
}
else {
player.sendMessage("<Torch> In use by someone else. Try later, dude. ");
}
}
else {
torchPlayer = player;
torchOn = true;
torchMove = true;
torchDistance = 10;
if (args.length > 1) {
if (isNumeric(args[1])) {
torchDistance = (int) toInteger(args[1]);
if (torchDistance < 1) {
player.sendMessage("<Torch> No! ");
torchOn = false;
}
else if (torchDistance > 50) {
player.sendMessage("<Torch> You really wanna turn the whole friggin' world into torches?!?! ");
torchOn = false;
}
}
else {
player.sendMessage("<Torch> Say what?");
}
}
if (torchOn) {
player.sendMessage("<Torch> On for a radius of " + torchDistance + ". ");
}
}
}
else if (args[0].equalsIgnoreCase("off")) {
if (torchOn) {
player.sendMessage("<Torch> What? You don't like torches any more? ");
torchOn = false;
}
else {
player.sendMessage("<Torch> Whatever, dude. ");
}
torchMove = false;
}
else {
player.sendMessage("<Torch> Huh? ");
}
}
else {
player.sendMessage("<Torch> Yo! ");
}
return (true);
}
return (false);
}
return (false);
}
@EventHandler
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player == torchPlayer) {
if (player.isOp()) {
torchMove = true;
}
else {
torchMove = false;
}
}
}
private static boolean isNumeric(String str) {
double d = 0;
if (d == 0) {
try {
d = Double.parseDouble(str);
}
catch(NumberFormatException nfe) {
return (false);
}
}
return (true);
}
private long toInteger(String garbage) {
long bigNumber = 0;
int inputIx = 0;
String sign = null;
String inputChar = "";
int inputDigit = 0;
garbage = garbage.trim();
bigNumber = 0;
if ((garbage.length() > 0) && (garbage.length() <= 18)) {
inputChar = garbage.substring(0,1);
inputIx = 0;
sign = "+";
if (inputChar.equals("-")) {
sign = "-";
inputIx = 1;
inputChar = garbage.substring(1,2);
}
while ((inputIx < garbage.length()) && ((inputChar.equals("0") || (inputChar.equals("1")) || (inputChar.equals("2")) || (inputChar.equals("3")) || (inputChar.equals("4")) || (inputChar.equals("5")) || (inputChar.equals("6")) || (inputChar.equals("7")) || (inputChar.equals("8")) || (inputChar.equals("9"))))) {
inputDigit = 0;
if (inputChar.equals("1")) inputDigit = 1;
else if (inputChar.equals("2")) inputDigit = 2;
else if (inputChar.equals("3")) inputDigit = 3;
else if (inputChar.equals("4")) inputDigit = 4;
else if (inputChar.equals("5")) inputDigit = 5;
else if (inputChar.equals("6")) inputDigit = 6;
else if (inputChar.equals("7")) inputDigit = 7;
else if (inputChar.equals("8")) inputDigit = 8;
else if (inputChar.equals("9")) inputDigit = 9;
bigNumber = bigNumber * 10;
bigNumber = bigNumber + inputDigit;
inputIx = inputIx + 1;
if (inputIx < garbage.length()) inputChar = garbage.substring(inputIx,inputIx + 1);
}
if (inputChar.equals("-")) {
sign = "-";
}
if (sign.equals("-")) {
bigNumber = bigNumber * -1;
}
}
return (bigNumber);
}
/*
@EventHandler
public void onTick(GameTick event) {
}
/* */
private void onTick() {
int playerX = 0;
int playerY = 0;
int playerZ = 0;
int subX = 0;
int subY = 0;
int subZ = 0;
Block block = null;
Block blockUnder = null;
if (torchOn) {
if (torchPlayer.isOp()) {
// torchPlayer.sendMessage("<Torch> Tick! ");
if (torchMove) {
// torchPlayer.sendMessage("<Torch> You moved! ");
torchMove = false;
Location loc = torchPlayer.getLocation();
playerX = loc.getBlockX();
playerY = loc.getBlockY();
playerZ = loc.getBlockZ();
subX = playerX - torchDistance;
while (subX <= playerX + torchDistance) {
subZ = playerZ - torchDistance;
while (subZ <= playerZ + torchDistance) {
subY = playerY - torchDistance;
while (subY <= playerY + torchDistance) {
block = getServer().getWorld(torchPlayer.getWorld().getUID()).getBlockAt(subX, subY, subZ);
if (block.getType() == Material.AIR) {
blockUnder = getServer().getWorld(torchPlayer.getWorld().getUID()).getBlockAt(subX, subY - 1, subZ);
if (subY <= 50) {
if ((blockUnder.getType() != Material.AIR) && (blockUnder.getType() != Material.TORCH)) {
block.setType(Material.TORCH); // <-- Spigot
// myServer.getWorld(torchPlayerWorld).setBlockAt(subX, subY, subZ, myServer.getBlockFromName(BlockHelper.getBlockName(MC_BlockType.TORCH)), 0); // <-- Rainbow
}
}
else if (subY <= 60) {
if ((blockUnder.getType() == Material.STONE) && (blockUnder.getType() != Material.TORCH)) {
block.setType(Material.TORCH); // <-- Spigot
// myServer.getWorld(torchPlayerWorld).setBlockAt(subX, subY, subZ, myServer.getBlockFromName(BlockHelper.getBlockName(MC_BlockType.TORCH)), 0); // <-- Rainbow
}
}
}
subY = subY + 1;
}
subZ = subZ + 1;
}
subX = subX + 1;
}
}
}
}
}
// private void doNothing() { }
}