onSignInteract Event

Discussion in 'Plugin Development' started by stantheman68, Aug 13, 2012.

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

    stantheman68

    Hey bukkit forums, Ive been having quite some trouble with this and I need help. I was making a plugin that had to deal with onSignInteract events and when I exported it and right clicked the sign nothing would happen. But when I created the sign, that is when it would send me the message. Here is the code for the main class:
    Code:
    package me.stantheman68.signrules;
     
    import java.util.logging.Logger;
     
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SignRules extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static SignRules plugin;
        public final PlayerListener pl = new PlayerListener();
        public int number = 10;
       
        @Override
        public void onDisable() {
            this.logger.info("Disabled!");
        }
       
        @Override
        public void onEnable() {
            this.logger.info("Enabled!");
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents((Listener) pl, this);
        }
    }
       
    
    Here is the code for the listener:
    Code:
    package me.stantheman68.signrules;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
     
    public class PlayerListener implements Listener{
       
        public static SignRules plugin;
       
        public void SignRules(SignRules instance) {
            plugin = instance;
        }
     
        @EventHandler
        public void onSignInteract(SignChangeEvent event) {
            Player player = event.getPlayer();
            if(event.getLine(0).equalsIgnoreCase("[SignRules]")){
                event.setLine(0, ChatColor.AQUA + "[Rules]");
                player.sendMessage(ChatColor.GOLD + "[" + ChatColor.WHITE + "SignRules" + ChatColor.GOLD + "]");
                player.sendMessage(ChatColor.GOLD + "1. (Rule)");
                player.sendMessage(ChatColor.GOLD + "2. (Rule)");
                player.sendMessage(ChatColor.GOLD + "3. (Rule)");
            }
                {
            }
        }
    }
    
     
  2. Offline

    Jogy34

    You are using a sign change event which should fire when you click the ok button in the sign GUI
     
  3. Offline

    Rockslide

    The is no "SignInteractEvent".

    The SignChangeEvent you are using fires when the text on the sign changes.

    If you want something to happen when you punch the sign, or right click it, use a PlayerInteractEvent.
    Then do event.getBlock() and see if it is a sign.
     
  4. Offline

    WarmakerT

    Code:
    public void onSignInteract(PlayerInteractEvent event){
    if(event.getRightClicked().getState() instanceof Sign){
    Sign sign = (Sign) event.getRightClicked().getState();
    sign.setLine(0, /*Stuff here*/);
    event.getPlayer().sendMessage();
    //
    //
    }
    }
     
  5. Offline

    stantheman68

    When I put that in, it will give me an error on event.getRightClicked().getState();
     
  6. Offline

    WarmakerT

    The error is?
     
  7. Offline

    stantheman68

    Im not quite sure it will underline it red then I hovered over it and it said "Change cast of 'event' "
     
  8. Offline

    WarmakerT

    *getClickedBlock()
     
  9. Offline

    stantheman68

    Thank you very much it worked :)
     
Thread Status:
Not open for further replies.

Share This Page