I asked a chatGPT bot to write a plugin with a simple task of placing a block of glowstone when executing a command “/example block”
How’d it do?
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class ExamplePlugin extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
// Register the "placeblock" command
getCommand("placeblock").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
// Get the block below the player's location
Material blockType = player.getLocation().subtract(0, 1, 0).getBlock().getType();
// Check if the block below is air
if (blockType == Material.AIR) {
// Place a block of stone below the player's location
player.getLocation().subtract(0, 1, 0).getBlock().setType(Material.STONE);
player.sendMessage("Block placed!");
} else {
player.sendMessage("There's already a block below you.");
}
return true;
}
return false;
}
}