BeeHives

Discussion in 'Plugin Development' started by Donkelyn, Aug 23, 2020.

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

    Donkelyn

    Heya, this is my current code for a way to change the way beehives work in order to speed them up. I'm having issues with the code and the current output is "1", "3", "5". This makes me believe that it stops when trying to convert the block into a beehive. Is there anyway to fix this? Thanks!


    Code:
    public class beeKeeper implements Listener {
    
        @EventHandler
        public void bees(EntityEnterBlockEvent e) {
            Bukkit.getServer().broadcastMessage("1");
            Entity ent = e.getEntity();
            if (ent.getType() != EntityType.BEE) {
                Bukkit.getServer().broadcastMessage("2");
                return;
            }
            Bukkit.getServer().broadcastMessage("3");
           
            Block b = e.getBlock();
            if (b.getType() != Material.BEEHIVE) {
                Bukkit.getServer().broadcastMessage("4");
                return;
            }
            Bukkit.getServer().broadcastMessage("5");
           
            honeyCheck((Beehive) b);
        }
    
        private void honeyCheck(Beehive h) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    Bukkit.getServer().broadcastMessage("6");
                    int honey = h.getHoneyLevel();
                    if (honey > 0) {
                        Bukkit.getServer().broadcastMessage("7");
                        h.setHoneyLevel(5);
                    }
                   
                }
                }.runTaskLater(main.plugin, 100);
            }
        }
     
  2. Offline

    KarimAKL

    @Donkelyn
    1. Please follow the Java naming conventions.
    2. You can use Bukkit.broadcastMessage(...) instead of Bukkit.getServer().broadcastMessage(...).
    3. It shouldn't be stopping, it should be waiting 100 ticks (5 seconds) before anything happens. If it did indeed stop on casting the block to a Beehive, it'd be because of a ClassCastException being thrown, which i'm assuming doesn't happen in this case.
     
Thread Status:
Not open for further replies.

Share This Page