Hey guys I need some help with this plugin that I am developing. Problem: it wont broadcast a message when someone breaks a Diamond Block. Here is my EventHandler: Code: package com.rtmplays.main.event; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; public class BlockBreak implements Listener { @EventHandler public void onBLockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); Material material = block.getType(); if(material == Material.DIAMOND_BLOCK) { Bukkit.broadcastMessage(player.getName() + ", Found a Diamond!"); } } } This is my main class: Code: package com.rtmplays.main; import java.util.logging.Logger; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.rtmplays.main.event.BlockBreak; public class Main extends JavaPlugin { public void onEnable() { PluginDescriptionFile pdfFile = getDescription(); Logger logger = getLogger(); registerEvents(); logger.info("******************************"); logger.info("Enabling.. " + pdfFile.getName() + " Version: " + pdfFile.getVersion()); logger.info("By RexTheMon"); logger.info("******************************"); } public void onDisable() { PluginDescriptionFile pdfFile = getDescription(); Logger logger = getLogger(); logger.info("******************************"); logger.info("Disabling.. " + pdfFile.getName() + " Version: " + pdfFile.getVersion()); logger.info("By RexTheMon"); logger.info("******************************"); } public void registerEvents() { PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new BlockBreak(), this); } }
@RexTheMon You're trying to make it to where it broadcasts if it's a Diamond BLOCK, right? Not a Diamond ORE? Im just asking because it says "Found a diamond", which makes me thing that you're trying to make it to where you have to break the ORE. If you are, change it to Material.DIAMOND_ORE If not, I don't really know what's wrong You can try not using lots of variables though, just do Code: @EventHandler public void onBreak(BlockBreakEvent e) { Player player = e.getPlayer(); if(e.getBlock().getType() == Material.DIAMOND_BLOCK) { Bukkit.broadcastMessage(player.getName()+", Found a Diamond!");
@RexTheMon Do you have any error in the console? if yes paste here the stack trace. In the broadcast message you should put Diamond Block instead of Diamond if you want a Diamond Block. If you want a Diamond_Ore and you are testing the plugin breaking a diamong ore but in fact you coded a diamond block you need to change it!
@RexTheMon you messed up the registerEvents thing in the onEnable, it should be Code: getServer().getPluginManager().registerEvents(this, this); Also why don't you just have it in 1 class file? Its small enough not to get lost right?
@boomboompower No No No No No. "this" refers to the same instance, only if the plugin itself is a listener and you want to register the events for that class you use "this", else you need to use the instance of the listener
I am trying to make it so when you break a Diamond Ore it broadcasts a message to the whole server. Also I do not have any console errors. @boomboompower I know @bwfcwalshy I have been learning from the TheBCBroz. The tutorial he was doing made me want to make a plugin! @SuperSniper Thanks! I will try Diamond_Ore instead.
He teaches really bad practices. Read the thread I posted and look around the forum. There are 1000's of posts on why he is bad.
Try: Code: if(e.getBlock().getType().equals(Material.DIAMOND_BLOCK)){ instead of Code: if(e.getBlock().getType()==Material.DIAMOND_BLOCK){
Could checking for the instance of the Block's state make a difference instead? And I would use ".equals(...)", it's more preferable.
@RexTheMon If you insist on watching someone try PogoStick29dev otherwise if you don't mind reading the best tutorials are the official ones.
I do watch him. Lol! Whats a good place to put my plugins for use, so they will get out there fast? <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>