Java Tutorial: Bukkit Plugin Development 1&2

Post here is you are having problems with any of the tutorials.
Post Reply
junrall
Posts: 2
Joined: Thu Sep 15, 2011 2:09 am

Java Tutorial: Bukkit Plugin Development 1&2

Post by junrall »

Hi Jacek,

I have been watching your Java Tutorial: Bukkit Plugin Development series and have been having an issue with it. I posted a message on one of your Youtube videos... you asked me to post my code here.

I've have watched the first two videos and have followed the TNTNotifier example as far as the second video.
I'm having a bit of a problem in that when TNT is placed nothing happens... TNT does not turn to cake, nor are there any messages written to the console indicating that TNT has been placed..

-The plugin is being logged to the console as being enabled.
=I have no errors when compiling.
I'm not using any other plugins.
-There are no errors in the console.
-And I have triple checked my code to be sure that it matches what was shown in the videos. (Though, very possible I can't see what I missed.)

I'm using:
The latest Bukkit
Eclipse Version: Indigo
Java development 7

Is it possible that the latest Bukkit has changes that will effect this programming example?

Here is my code:
plugin.yml
name: TNTNotifer
version: 0.1
main: duh.TNTNotifier
TNTNotifier.java
package duh;

import java.util.logging.Logger;

import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class TNTNotifier extends JavaPlugin{

	private Logger log = Logger.getLogger("Minecraft");
	
	public void onEnable() {
        PluginManager pm = this.getServer().getPluginManager();
		
		pm.registerEvent(Event.Type.BLOCK_PLACE, new TNTNotifierBlockListener(this), Priority.Highest, this);
		
		this.logMessage("Enabled");
	}
	
	public void onDisable() {
				
		this.logMessage("Disabled");
	}	
	
	protected void logMessage(String msg) {
		// TNTNotifier version#: msg
		PluginDescriptionFile pdFile = this.getDescription();
		
		this.log.info(pdFile.getName() + " " + pdFile.getVersion() + ": " + msg);
	}
		
}
TNTNotifierBlockListener.java
package duh;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;

public class TNTNotifierBlockListener extends BlockListener {

	private TNTNotifier plugin;
	
	public TNTNotifierBlockListener(TNTNotifier instance){
		this.plugin = instance;
	}
	
	public void OnBlockPlace(BlockPlaceEvent event){
		if (event.isCancelled())
			return;
		
		Block block = event.getBlock();
		Player player = event.getPlayer();
		
		if (block.getType() == Material.TNT){
			
			block.setType(Material.CAKE_BLOCK);
			
			player.sendMessage(ChatColor.RED + "No TNT Allowed!");
			
			plugin.logMessage(player.getName() + "Placed TNT at " + block.getX() + "'" + block.getY() + "," + block.getZ());
		}
	}
	
}
Thanks for taking the time to look at this. I do appreciate it!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Java Tutorial: Bukkit Plugin Development 1&2

Post by jacek »

junrall wrote:Hi Jacek,
Hello :D
junrall wrote:Is it possible that the latest Bukkit has changes that will effect this programming example?
It is, but the videos were done on RB1060 and that has been the latest build for some time now. Also it is very unlikely that the simplest things will be changed.

The problem is a irritatingly simple one...
public void OnBlockPlace(BlockPlaceEvent event){
should be
public void onBlockPlace(BlockPlaceEvent event){
with a lower-case o as the first character of the method name.
Image
junrall
Posts: 2
Joined: Thu Sep 15, 2011 2:09 am

Re: Java Tutorial: Bukkit Plugin Development 1&2

Post by junrall »

Gaaah! Capitalization comes from working with Visual Basics OnClick events and similar what nots!

Thank you!
Post Reply