Java Tutorial: Bukkit Plugin Development 1&2
Posted: Thu Sep 15, 2011 2:31 am
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
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.TNTNotifierTNTNotifier.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!