blocklistener help

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

  1. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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

    This post has been edited 3 times. It was last edited by jacklin213 Jun 20, 2012.
  2. Offline

    zhuowei

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.

    This post has been edited 1 time. It was last edited by zhuowei Jun 20, 2012.
  3. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @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.

    This post has been edited 1 time. It was last edited by r0306 Jun 21, 2012.
    zhuowei likes this.
  4. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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. Offline

    zhuowei

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    but the command did work ??
  7. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Code:
    public void onEmpty(PlayerBucketEmptyEvent event) {
      Player player = event.getPlayer();
      if (event.getBucket() = Material.LAVA_BUCKET) {
         player.sendMessage("BEWARE no grefing with the lava!");
      }
    }
    

    This post has been edited 1 time. It was last edited by r0306 Jun 21, 2012.
  8. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306 u didnt make bucket a variable so it isnt working
    how do i fix that?

    This post has been edited 2 times. It was last edited by jacklin213 Jun 21, 2012.
  9. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  10. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You don't need a variable. What part of the code is not working?
  11. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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

    This post has been edited 1 time. It was last edited by jacklin213 Jun 21, 2012.
  12. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @jacklin213
    Oh. I used the wrong operator. Use "==" instead of "=".
    Code:
    if (event.getBucket() == Material.LAVA_BUCKET) {
    
  13. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306 what do i put if i wanted it to warn me when i break a block eg)leaves
  14. Offline

    ThatBox

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Do you have any experience with java?
  15. Offline

    jacklin213

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)

Share This Page