Delete this thread please

Discussion in 'Plugin Development' started by Tzahi, Jun 22, 2011.

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

    Tzahi

    Thank you for taking your time reading this. I am developing my first plugin called LavaPlace. The features is that it says when lava is placed and it specifies the person. It also says when bedrock and TNT are placed. And by lava I mean a lava bucket, not the item code 10 or 11.

    So I got TNT and Bedrock working, but why isn't Lava working?

    if (block.getType() == Material.LAVA) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed Lava");
    }




    Of course I have code before this, but I just want the material correct and everything working properly. If you need more code to fix this, let me know.

    Thanks.

    package me.tzahi.LavaPlace;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.event.block.BlockPlaceEvent;
    public class BasicBlockListener extends BlockListener {
    public static LavaPlace plugin;
    public BasicBlockListener(LavaPlace instance) {
    plugin = instance;

    }
    public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlockPlaced();
    if (block.getType() == Material.TNT) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed TNT");
    }
    if (block.getType() == Material.BEDROCK) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed Bedrock");
    if (block.getType() == Material.LAVA) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed Lava");
    }

    }
    }
    }



    This is my whole BlockListener class file.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  2. Offline

    Bone008

    The thing is that a BLOCK_PLACE-event isn't called when a player uses a bucket (since he doesn't place a block ...).
    I believe the event for bucket-placements is called PLAYER_BUCKET_EMPTY.
     
  3. Offline

    Tzahi

    Ok, thanks, I'll see if I can figure it out.

    @Bone008 Ok, I can't figure it out. Can you help me out? Thanks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  4. Offline

    Bone008

    @Tzahi
    Just register the PLAYER_BUCKET_EMPTY-event in your main-class (like you hopefully did with the BLOCK_PLACE-event) and create a class extending the PlayerListener for it.
    http://wiki.bukkit.org/HUGE_Plugin_Tutorial#Listeners

    Then just define your onPlayerBucketEmpty-method as usual:
    Code:
    @Override
    public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event){
        // your code
    }
     
  5. Offline

    Tzahi

    @Bone008

    Ok, I did that. Is this correct? I got an error line for playerListener.

    pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this);



     
  6. Offline

    Bone008

    Did you define the variable playerListener in your main-class?
    Something like that:
    Code:
    private final YOUR_LISTENER_CLASS_NAME playerListener = new YOUR_LISTENER_CLASS_NAME(this);
     
  7. Offline

    Tzahi

    Ok, sorry for bothering you so much, but how do I set up the if statement? This is what I got so far.

    package me.tzahi.LavaPlace;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerBucketEmptyEvent;
    import org.bukkit.event.player.PlayerListener;

    public class BasicPlayerListener extends PlayerListener {
    public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
    Player player = event.getPlayer();
    if (Item == Material.LAVA_BUCKET) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed Lava");
    }

    }
    }
     
  8. Offline

    Bone008

    You should be using an IDE like Eclipse, so you should see every available method for a PlayerBucketEmptyEvent.
    Just play around with them until you figure out what to use! That way you will learn a lot quicker.
    I recommend you to also check out the javadoc. Without ever using this event I would say you either need to use getBucket() or getItemStack(). Just try it!
     
  9. Offline

    Tzahi

    I'm not home right now but when I do I'll try it. Thanks for the info and help :)

    Would this be correct?

    public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
    Player player = event.getPlayer();
    if (Material.BUCKET == Material.LAVA_BUCKET) {
    plugin.getServer().broadcastMessage(ChatColor.RED + player.getName() + " placed Lava");
    }

    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  10. Offline

    Bone008

    Nearly, but this should even seem weird to someone who doesn't know anything about programming ;)
    Code:
    Material.BUCKET == Material.LAVA_BUCKET
    Comparing two different Materials obviously never returns true. try event.getBucket() instead of Material.BUCKET ;)
     
  11. Offline

    Tzahi

    Last edited by a moderator: May 16, 2016
Thread Status:
Not open for further replies.

Share This Page