Sign Stuff :3

Discussion in 'Plugin Development' started by HyrulesLegend, Sep 5, 2013.

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

    HyrulesLegend

    So, I've been messing with signs lately, and I was wondering how I would go about adding a part to my current code, so I can check a line on a sign, and if it a certain phrase/word is there, it does something. I just basically need to know how to go about checking the line and checking for the word/phrase. (Also if you could help, not that its needed, if you could help me specify to make it RIGHT_CLICK_BLOCK, and how I should work with that, cause currently it works with both clicks.

    Current Code:
    Code:
    package me.maxtheorange.Signs;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    public class PvP implements Listener{
     
           
            public PvP(Main instance){
                    @SuppressWarnings("unused")
    Main plugin = instance;
            }
            @EventHandler
            public void signClick(PlayerInteractEvent e)
            {
              Player p = e.getPlayer();
                if ((e.getClickedBlock() .getType() == Material.WALL_SIGN) || (e.getClickedBlock().getType() == Material.SIGN_POST)) {
               e.getAction();
    if ((org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK ) != null);
               p.sendMessage(ChatColor.GOLD + "You have clicked a sign!");
                }
            }
    }
                
    
     
  2. Offline

    jay275475

    Max I need this Also For A GUI Shop Im making
     
  3. Offline

    kbunkrams97

    jay275475 Max_The_Link_Fan
    First you will want to check and make sure that the block state is a sign then create a variable with the sign. To do that you need to do:
    Code:java
    1. if(event.getClickedBlock().getState() instanceof Sign)
    2. {
    3. Sign sign = (Sign) event.getClickedBlock().getState();
    4. }


    Now once you have done that you can use commands like sign.getLine(0);
     
  4. Offline

    xTrollxDudex

  5. Offline

    HyrulesLegend

    kbunkrams97
    Code:java
    1. if ((e.getClickedBlock() .getType() == Material.WALL_SIGN) || (e.getClickedBlock().getType() == Material.SIGN_POST)) {
    2. e.getAction();
     
  6. Offline

    CeramicTitan

    That code is wrong, That's why it isn't working. Please go watch/read some tutorials.

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e){
    3. //Declare your variables
    4. Block b = e.getClickedBlock();
    5. Player p = e.getPlayer();
    6. //Check the actions first
    7. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    8. //Check if the block clicked is a sign
    9. if (b.getType() == Material.WALL_SIGN || (e.getClickedBlock().getType() == Material.SIGN_POST)) {
    10. //Send the message
    11. p.sendMessage(ChatColor.GOLD + "You have clicked a sign!");
    12. }
    13. }
    14. }
     
  7. Offline

    HyrulesLegend

    CeramicTitan
    Code:java
    1. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)

    That line gives me an error, simply asking to "rename in file" on the "RIGHT_CLICK_BLOCK" action.
     
  8. Offline

    CeramicTitan

    what?
     
Thread Status:
Not open for further replies.

Share This Page