Plugin break/smelt events don't work

Discussion in 'Plugin Development' started by Wolfie, Jan 20, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Wolfie

    I'm writing a plugin for my server but the block break and the smelting events don't work. The /withdraw command does work though, and no errors are shown in the console when the events are attempted to be ran.

    Code:
    package me.wolfie;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.inventory.FurnaceExtractEvent;
    import org.bukkit.event.inventory.FurnaceSmeltEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin implements Listener{
        public final Logger logger = Logger.getLogger("Minecraft");
        public Main plugin;
        public int build;;
        @Override
        public void onEnable(){
            build = 1;
            logger.info("DogeCraftTips Build " + build + " successfully enabled. Whoo hoo!");
            Bukkit.getPluginManager().registerEvents(this, this);
        }
        @Override
        public void onDisable(){
        logger.info("DogeCraftTips Build " + build + " has been disabled.");
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("withdraw")) { // If the player typed /basic then do the following...
               sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Due to the DogeTips plugin being broken, please just contact /u/WShibe on Reddit or ingame as IAmTheWolfie.");
                return true;
            } //If this has happened the function will return true.
                // If this hasn't happened the value of false will be returned.
            return false;
        }
    public void onBlockBreak2(BlockBreakEvent eb){
        //Diamonds
            if(eb.getBlock().getType() == Material.DIAMOND_ORE){
                eb.setExpToDrop(3);
                eb.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 5 doge for mining a diamond!");
                getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + eb.getPlayer().getDisplayName() + "5");
                }
    
    }
    //Smelting Iron
    public void  onFurnaceSmelt(FurnaceSmeltEvent event, FurnaceExtractEvent e){
        if(event.getResult().getType() == Material.IRON_INGOT) {
            e.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 2 doge for smelting an iron!");
            getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + e.getPlayer().getDisplayName() + "2");
        }
    }
    
    public void onBlockBreak3(BlockBreakEvent ea){
        //Lapis
            if(ea.getBlock().getType() == Material.LAPIS_ORE){
                ea.setExpToDrop(3);
                ea.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 2 doge for mining lapis!");
                getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + ea.getPlayer().getDisplayName() + "2");
                }
    
    }
    
    public void  onFurnaceSmelt2(FurnaceSmeltEvent event, FurnaceExtractEvent e){
                if(event.getResult().getType() == Material.GOLD_INGOT) {
                    e.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 3 doge for smelting an iron!");
                    getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + e.getPlayer().getDisplayName() + "3");
                }
            }
    public void onBlockBreak5(BlockBreakEvent eab){
        //Coal
            if(eab.getBlock().getType() == Material.COAL_ORE){
                eab.setExpToDrop(3);
                eab.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 0.2 doge for mining coal!");
                getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + eab.getPlayer().getDisplayName() + "0.2");
                }
    
    }
    public void onBlockBreak6(BlockBreakEvent eaba){
        //Redstone
            if(eaba.getBlock().getType() == Material.REDSTONE_ORE){
                eaba.setExpToDrop(3);
                eaba.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 2 doge for mining redstone!");
                getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + eaba.getPlayer().getDisplayName() + "2");
                }
    
    }
    public void onBlockBreak7(BlockBreakEvent eabb){
        //Emerald
            if(eabb.getBlock().getType() == Material.EMERALD_ORE){
                eabb.setExpToDrop(3);
                eabb.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Congratulations! You've gotten 10 doge for mining emerald!");
                getServer().dispatchCommand(getServer().getConsoleSender(), "dogetips " + eabb.getPlayer().getDisplayName() + "10");
                }
    
    }
    }
    
    
    Any help?
     
  2. Offline

    Javlin

    Forgetting @EventHandler?
     
  3. Offline

    Zombie_Striker

    Please stick to package naming conventions.
    Don't steal minecraft's logger!!!! Use .getLogger instead.

    If you're only going to have one class, you do not need this especially since you did not even set plugin to anything.
    1. What is the use of this.
    2. You only need one semicolon.

    You do not need to log your own plugin. Bukkit does this for you.
    Because of the above comment, you do not even need this method.
    The following all tells me you have no idea what you're doing:
    1. You forgot the EventHandler tags
    2. You couple events, which would NEVER work.
    3. Your formatting is terrible.
    4. Your naming is unconventional.
    5. You are duplicating events.
    These are all clear signs that you do not fully understand Java. Bukkit REQUIRES you to have knowledge of Java before moving onto bukkit. Please, find a good tutorial at this link, take a month to learn, and come back. PLEASE DO NOT IGNORE THIS.
     
    JoaoBM and Javlin like this.
  4. Offline

    Wolfie

    @Zombie_Striker Agh shit, I just realized that I don't need like 5 million events. Where would I put the EventHandler tags? I really suck at this lol
     
  5. Offline

    Javlin

    Right before the method.
     
  6. Offline

    Wolfie

    @Javlin Thanks for the help and putting up with my stupidity lol

    @Javlin aaand it didn't work :/


    (merged by moderator)
     
    Last edited by a moderator: Jan 20, 2016
  7. Offline

    mcdorli

    Show us your current code
     
  8. Offline

    ShowbizLocket61

    @Wolfie
    You have the @EventHandler tag, right? Now separate your coupled event listener, and group together the ones with the same event.
     
Thread Status:
Not open for further replies.

Share This Page