Solved Counting lava doesn't work

Discussion in 'Spigot Plugin Development' started by KevinDasPikachu, Aug 1, 2020.

Thread Status:
Not open for further replies.
  1. I wrote a Listener that checks how much Lava a player has placed but I am not getting my p.sendMessage() so what is wrong with my code?
    Code (Java):
    package me.Kevin.Listener;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitRunnable;

    import me.Kevin.main.main;
    import me.Kevin.utils.Alerts;

    public class LS_Alert_Lava implements Listener
    {
        private main plugin;
       
        int lavaAlerts, alerts;
        long ticks, seconds, minutes, delay;
       
        public LS_Alert_Lava(main plugin)
        {
            this.plugin = plugin;
        }
       
        public void onLava(BlockPlaceEvent e)
        {
            Material blockType = e.getBlockPlaced().getType();
           
            if (blockType == Material.LAVA_BUCKET)
            {  
                Player p = e.getPlayer();
               
                int chosenLavaAlertInt = 5;
                boolean ignorePortals = false;

                if (!Alerts.cfg.contains("Alerts " + p.getName() + " Lava" + ": "))
                {
                    Alerts.cfg.set(("Alerts " + p.getName() + " Lava" + ": "), 0);
                }
               
                alerts = Alerts.cfg.getInt("Alerts " + p.getName() + ": ");
                lavaAlerts = Alerts.cfg.getInt("Alerts " + p.getName() + " Lava" + ": ");
               
                ticks = 20L; // 1 minute = 20 ticks
                seconds = 60L; // 1 minute = 60 seconds
                minutes = 1L; //only change this
               
                delay = ticks*seconds*minutes;
               
                HashMap<Player, Integer> lavaPlacedHM = new HashMap<Player, Integer>();
                lavaPlacedHM.put(p, lavaPlacedHM.get(p) + 1);
               
                int lavaPlaced = lavaPlacedHM.get(p);
               
                p.sendMessage("aaaaaaaaa" + lavaPlaced); //for debug reasons

                if (lavaPlaced == 0)
                {
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
                    {
                       
                        @Override
                        public void run()
                        {
                            if (lavaPlaced >= chosenLavaAlertInt)
                            {
                                lavaAlerts++;
                               
                                if (ignorePortals)
                                {
                                    if (lavaPlaced == 10)
                                    {
                                        lavaAlerts--;
                                    }
                                }
                            }
                           
                            if (lavaAlerts != 0)
                            {
                                Alerts.cfg.set("Alerts" + p.getName() + ": ", alerts + lavaAlerts);
                            }
                           
                            Alerts.cfg.set("Alerts" + p.getName() + ": ", alerts);
                            Alerts.cfg.set("Alerts" + p.getName() + " Lava" + ": ", lavaAlerts);
                            main.SaveFile();
                           
                            lavaPlacedHM.put(p, 0);
                        }
                    }, 0, delay);
                   
                }
            }
        }
    }
     
     
  2. The problem is on the Material, you are checking if the player is placing the item, and no the lava block
     
  3. I don't seem to get a message even after changing this.
     
  4. LAVA_BUCKET is not a block, it's a material
    Check if the blockPlaced type is Material.LAVA
     
  5. I don't see the EventHandler annotation on top of the method that should listen
     
    • Agree Agree x 1
  6. I changed the material to Material.LAVA and added @EventHandler and it still doesn't work.
     
  7. It's because the lava isn't a Block, I think, I tested using BlockPlaceEvent with Lava, and nothing happened... I recommend you to use another Event how Interact Event
     
  8. InteractEvent isn't for such things. Also why would the other event would have Material.LAVA if that wouldn't do anything.
     
  9. It seems like if I only take the event it doesn't notice me placing lava even with Material.LAVA. Which event should I use instead?
     
  10. PlayerInteractEvent with right click and if the player has a lava bucket in his hand doesn't work because if he would right-click in the air the event would still be triggered
     
  11. You can check if event#getAction() == Action.RIGHT_CLICK_BLOCK
     
  12. Thank you I have never used the InteractEvent before so I didn't know this I will try this out rn.
     
  13. Have you figured this out yet? You just forgot the @EventHandler on top of your method. Also, did you register this on your onEnable?
     
  14. I registered the event properly.
     
  15. On top of what the others said, there is a PlayerBucketEmptyEvent.
     
    • Agree Agree x 1
  16. I am currently trying out a simplified version of my code which is
    Code (Java):
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onLava(PlayerInteractEvent e)
        {
                Player p = e.getPlayer();
               
                if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().equals(Material.LAVA_BUCKET))
                {
                    p.sendMessage("BAUMSPECHT");
                }
     
  17. It doesn't work.
     
  18. Register the event listener.
     
  19. Obviously... an itemstack will never equal a material.
     
  20. You just need to detect when a player places a lava "block", right?
     
Thread Status:
Not open for further replies.