[Help] Signs give messages.

Discussion in 'Plugin Development' started by Theodossis, Mar 24, 2012.

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

    Theodossis

    I am new at craftbukkit developing with eclipse and 1 of thing i want to know is how i can send messages by pressing right click in sign.
    Sign Example:
    [News] <-------- I want to do this in sign and when i press right click in sign the player would take a msg.
     
  2. Offline

    Lolmewn

    This is part of my Sortal plugin, hope it's helpful. You can so s.getLine(0) and check if it's [News]
    Code:
    @EventHandler
        public void onPlayerHitSign(PlayerInteractEvent event) {
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
                Block b = event.getClickedBlock();
                if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.SIGN_POST)
                        || b.getType().equals(Material.WALL_SIGN)) {
                    //It's a sign
                    Sign s = (Sign) b.getState();
     
  3. Offline

    Theodossis

    I got this is it right?
    @EventHandler

    publicvoid onPlayerHitSign(PlayerInteractEvent event) {

    Player player = event.getPlayer();
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {

    Block b = event.getClickedBlock();
    if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
    Sign s = (Sign) b.getState();
    s.getLine(1).contains("[News]");
     
  4. Offline

    tobindev

    There is no publicvoid it's public void ;)
    And then you only have to check your last line
    Code:
    if(s.getLine(1).contains("[News]") {
    //do this stuff
    }
    
     
  5. Offline

    Theodossis

    Thank you!

    Is this right for my sign listener? Help please.Sign doesn't send the message!

    Code:
    package me.Theodossis.TheNews;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    public class TheNewsSignListener implements Listener {
        public static TheNews plugin;
     
        public TheNewsSignListener(TheNews instance) {
            plugin = instance;
        }
        @EventHandler
        public void onPlayerHitSign(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
                    Block b = event.getClickedBlock();
                    if (b.getType().equals(Material.SIGN) && b.getType().equals(Material.SIGN_POST) && b.getType().equals(Material.WALL_SIGN)) {
                        Sign s = (Sign) b.getState();
                        if(s.getLine(1).contains("[News]")) {
                            player.sendMessage(ChatColor.GRAY + "###TheNews###");
                        }
                    }
            }
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  6. Code:
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    use OR instead of AND, or can you right click while left clicking :confused:
     
    Theodossis likes this.
  7. Offline

    Theodossis

  8. I just noticed, same applies to this line:
    Code:
     if (b.getType().equals(Material.SIGN) && b.getType().equals(Material.SIGN_POST) && b.getType().equals(Material.WALL_SIGN)) {
     
  9. Offline

    Theodossis

    How is or? Like that || ?
     
  10. yep.
     
  11. Offline

    Theodossis

    Again it doesn't work... want all my plugin?
     
  12. try some debugging, like until when does the function get or if it's actually called at all.
     
  13. Offline

    Theodossis

    if you got skype add me
    name: theodossis4
     
  14. Offline

    theask

    Theodossis
    I know its old but try to use Index 0
    Current:
    s.getLine(1).contains("[News]")
    After:
    s.getLine(0).contains("[News]")
     
    McLuke500 likes this.
  15. Offline

    McLuke500

    Yeah it has to be 0 for first line 1 for second and so on. Then it should all work.
     
Thread Status:
Not open for further replies.

Share This Page