How to stop lava from being placed?

Discussion in 'Plugin Development' started by Nathat23, Dec 21, 2014.

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

    Nathat23

    Hello, I am making a plugin that stops buckets from being used, and I can't stop lava from being placed using
    Code:
    if (e.getItemInHand().getType() == Material.LAVA_BUCKET ) {
                if (!player.hasPermission("StopBucketFill.lavaplace")){
                    player.sendMessage(ChatColor.RED + "You are not allowed to place lava! Ask a admin for permission");
                    e.setCancelled(true);
                } else player.sendMessage(ChatColor.RED + "You are allowed to place lava!");
     
  2. Offline

    stoneminer02

    Do a BlockPlaceEvent.
    Check if block is LAVA or STATIONARY_LAVA.
    If true, cancel event.
    If false, ignore.
     
  3. Offline

    Nathat23

    How do I Check if block is LAVA or STATIONARY_LAVA?
     
  4. Offline

    Konato_K

    @Nathat23 Use Block#getType, however, this is not a good idea (unless you're giving lava as a block) since lava is usually placed with buckets, listen for PlayerBucketEmptyEvent and use PlayerBucketEmptyEven#getBucket to check the Material of the bucket :)
     
  5. Offline

    Nathat23

    Code:
    package me.Nathat23;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.player.PlayerBucketEmptyEvent;
    
    public class Lava implements Listener{
        public Lava(StopBucketFill plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void lava(PlayerBucketEmptyEvent e) {
            Player player = e.getPlayer();
            if (e.getBlockClicked().getType() == Material.LAVA) {
                if (!player.hasPermission("StopBucketFill.lavaplace")){
                    player.sendMessage(ChatColor.RED + "You are not allowed to place lava! Ask a admin for permission");
                    e.setCancelled(true);
                } else player.sendMessage(ChatColor.RED + "You are allowed to place lava!");
            }
            if (e.getBlockClicked().getType() == Material.STATIONARY_LAVA) {
                if (!player.hasPermission("StopBucketFill.lavaplace")){
                    player.sendMessage(ChatColor.RED + "You are not allowed to place lava! Ask a admin for permission");
                    e.setCancelled(true);
                } else player.sendMessage(ChatColor.RED + "You are allowed to place lava!");
            }
            }
        }
    
    So, that should work?
     
  6. Offline

    PreFiXAUT

    @Nathat23 Why are you asking us that? Try it out :confused: Try & Error is one of the best Methods to learn.
     
  7. Offline

    Nathat23

    Well, it crashes the whole plugin anyway :confused:
     
  8. Offline

    Konato_K

    @Nathat23 No, it wont, you're checking the block that the lava is being placed against, as I said, use getBucket method in the event.
     
Thread Status:
Not open for further replies.

Share This Page