blocklistener help

Discussion in 'Plugin Development' started by jacklin213, Jun 20, 2012.

Thread Status:
Not open for further replies.
  1. hi there im trying to develop a bukkit plugin for myself but when i try something like this
    Code:
    package me.jacklin213.basic;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BasicBlockListener implements Listener {
        public static Basic plugin;
        public BasicBlockListener(Basic instance) {
            plugin = instance;
        }
     
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            Block block = event.getBlockPlaced();
            if (block.getType() == Material.TORCH) {
                player.sendMessage("You have placed a torch!");
            if (block.getType() == Material.DIRT) {
                player.sendMessage("You have placed dirt!");
            if (block.getType() == Material.LAVA) {
                player.sendMessage("BEWARE no grefing with the lava!");
            }
            }
        }
    }
    }
    it only says something when i place dirt but if i put torch to the top like this

    Code:
    package me.jacklin213.basic;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BasicBlockListener implements Listener {
        public static Basic plugin;
        public BasicBlockListener(Basic instance) {
            plugin = instance;
        }
     
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            Block block = event.getBlockPlaced();
            if (block.getType() == Material.DIRT) {
                player.sendMessage("You have placed dirt!");
            if (block.getType() == Material.TORCH) {
                player.sendMessage("You have placed a torch!");
            if (block.getType() == Material.LAVA) {
                player.sendMessage("BEWARE no grefing with the lava!");
            }
            }
        }
    }
    }
    it only sends a message when i place torch. PLZ help me
     
  2. Code:
            if (block.getType() == Material.DIRT) {
                player.sendMessage("You have placed dirt!");
                if (block.getType() == Material.TORCH) {
                    player.sendMessage("You have placed a torch!");
                    if (block.getType() == Material.LAVA) {
                        player.sendMessage("BEWARE no grefing with the lava!");
                    }
                 }
            }
    That's your code, properly indented. This isn't Python.The { brace signifies that the following code is inside the if statement, and } signifies that the code is no longer in the if statement.
    Code:
            if (block.getType() == Material.DIRT) {
                player.sendMessage("You have placed dirt!");
            }
            if (block.getType() == Material.TORCH) {
                player.sendMessage("You have placed a torch!");
            }
            if (block.getType() == Material.LAVA) {
                player.sendMessage("BEWARE no grefing with the lava!");
            }
    Is probably what you meant.
     
  3. jacklin213
    Also, the event won't detect Lava placement because players are using a bukkit to place the lava. That should be handled in a BucketEmptyEvent instead.
     
    zhuowei likes this.
  4. kk ty zhuowei it works ty r0306 how would i do that?
    another question is when i active it by doing /b it would say

    Basic enabled (plugin name)
    b

    y does it say b under it ??
     
  5. The /b displays because the plugin returned false after processing the command, which means "The command didn't work, show the help file".
    Code:
    public void onCommand(...stuff
       if (label.equals("b")){
           //do stuff
           return true; //Successfully executed
       }
       return false; //unsuccessfully executed; show the player the help.
    }
     
  6. but the command did work ??
     
  7. Code:
    public void onEmpty(PlayerBucketEmptyEvent event) {
      Player player = event.getPlayer();
      if (event.getBucket() = Material.LAVA_BUCKET) {
         player.sendMessage("BEWARE no grefing with the lava!");
      }
    }
    
     
  8. r0306 u didnt make bucket a variable so it isnt working
    how do i fix that?
     
  9. Np.

    You don't need a variable. What part of the code is not working?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  10. Code:
    public void onEmpty(PlayerBucketEmptyEvent event) {
      Player player = event.getPlayer();
      if ("event.getBucket"() = Material.LAVA_BUCKET) {
        player.sendMessage("BEWARE no grefing with the lava!");
      }
    }
    i put in quote marks
     
  11. jacklin213
    Oh. I used the wrong operator. Use "==" instead of "=".
    Code:
    if (event.getBucket() == Material.LAVA_BUCKET) {
    
     
  12. r0306 what do i put if i wanted it to warn me when i break a block eg)leaves
     
  13. Do you have any experience with java?
     
  14. er kinda
     
Thread Status:
Not open for further replies.

Share This Page