Solved Cofuzzled

Discussion in 'Plugin Development' started by CraftCreeper6, Mar 14, 2015.

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

    CraftCreeper6

    Welp, I am confused to hell. For some reason, this doesn't seem to turn into an ingot o.o
    Code:
    @EventHandler
        public void onBlockBreak(BlockBreakEvent e)
            {
    
            Player player = e.getPlayer();
        
            Block block = e.getBlock();
            Material blockType = block.getType();
        
            ItemStack itemInHand = player.getItemInHand();
        
            if(player.getGameMode().equals(GameMode.CREATIVE)) return;
        
            if(!(oreList.contains(blockType)))
                {
                player.getInventory().addItem(new ItemStack(blockType, 1, block.getData()));
                }
            else if(oreList.contains(blockType))
                {
                if(itemInHand.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS))
                    {
                    int fortuneLevel = itemInHand.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
                    player.getInventory().addItem(new ItemStack(oreList.getChild(blockType), fortuneLevel*2, block.getData()));
                    }
                else
                    {
                    player.getInventory().addItem(new ItemStack(oreList.getChild(blockType), 1, block.getData()));
                    }
            
                }
        
            e.setCancelled(true);
            block.setType(Material.AIR);
        
            }
    The OreList.java class:
    Code:
    package lch.www.ores;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import org.bukkit.Material;
    
    public class OreList
        {
    
        private List<Material> oreList = new ArrayList<Material>();
        private HashMap<Material, Material> pairs = new HashMap<Material, Material>();
        private boolean setup = false;
       
        public boolean contains(Material material)
           {
            return oreList.contains(material);
           }
       
        public void setup()
           {
            Material[] ores = {Material.COAL_ORE, Material.IRON_ORE, Material.GOLD_ORE, Material.DIAMOND_ORE, Material.EMERALD_ORE};
            pairs.put(Material.COAL_ORE, Material.COAL);
            pairs.put(Material.IRON_ORE, Material.IRON_INGOT);
            pairs.put(Material.GOLD_ORE, Material.GOLD_INGOT);
            pairs.put(Material.DIAMOND_ORE, Material.DIAMOND);
            pairs.put(Material.EMERALD_ORE, Material.EMERALD);
            for(Material material : ores)
               {
                oreList.add(material);   
               }
            this.setup = true;
           }
       
        public Material getChild(Material ore)
           {
            if(setup)
               {
                return pairs.get(ore);
               } 
            else
               {
                return null;
               }
           }
       
        }
    
    
    
    
     
    Last edited: Mar 14, 2015
  2. Offline

    DamnHippo

    Instead of adding to player inventory try setting the block drop?
     
  3. Offline

    CraftCreeper6

    @DamnHippo
    I want automatic inventory also ;p
     
  4. Offline

    DamnHippo

    @CraftCreeper6 I did this on my ore payout. I just checked the event if the player was breaking iron ore and if they where, I gave them an iron ingot. Didn't use an ore list
     
  5. Offline

    Zombie_Striker

    Did you debug? What happens when you mine the block?
     
  6. Offline

    CraftCreeper6

    @Zombie_Striker
    I did infact debug, it says that getChild() is returning null all of the time, but why?
     
  7. Offline

    Zombie_Striker

    Is setup == FALSE? can you do a System.out of the the Materials name?
     
  8. Offline

    CraftCreeper6

    @Zombie_Striker
    I removed that line to check, and it still doesn't work.
     
  9. Offline

    Zombie_Striker

    Then pairs.getOre() is returning null, meaning that your pairs does not have that value in it.

    Is setup() ever called? Is pairs empty?
     
  10. Offline

    Plo124

    He is using a system that I think is more object-orientated, and easier to add/remove/edit ores.


    @CraftCreeper6
    Note: You should ALWAYS make sure to check if the blockbreakevent is cancelled before changing the outcome unless you are SURE you know what your doing. This is so block protection plugins (like WorldGuard) have a chance to block the player.
     
    CraftCreeper6 likes this.
  11. Offline

    CraftCreeper6

    @Zombie_Striker
    Fixed it, for some reason, my setup method wasn't getting called. (Even though I did call it...)
     
Thread Status:
Not open for further replies.

Share This Page