Yet Another Question

Discussion in 'Plugin Development' started by duckie33, Mar 9, 2012.

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

    duckie33

    This time i really apologize for the noobyness

    Im trying to write

    Code:java
    1.  
    2. @EventHandler
    3. public void test(PlayerInteractEvent event)
    4. {
    5. Player p = event.getPlayer();
    6. Block b = event.getClickedBlock():
    7.  
    8. if (b.getType().equals(Material.sign) && Has this text...equals("blabla")
    9. {
    10. do stuff
    11. }


    Is this possible?


    Thanks in advance! Great community :)
     
  2. Well, I don't think you can do that directly. You can still achieve that by saving the player in BlockPlace and later checking it.
     
  3. Offline

    duckie33

    Could you explain how, i tried a few ways but it doesn't seem to be working :/
     
  4. Code:java
    1.  
    2. onBP (BlockPlaceEvent e){
    3. Block b = e.getBlock();
    4. if(b.getType().equals(Material.SIGN)){
    5. Player p = b.getPlayer();
     
  5. Offline

    duckie33

    "The method getPlayer() is undefined for the Type Block"
     
  6. Offline

    duckie33

    Then i tried this, and it didn't send the message :/

    @EventHandler
    public void onBP (BlockPlaceEvent e){
    Block b = e.getBlock();
    if(b.getType().equals(Material.SIGN) )
    {
    Player p = e.getPlayer();

    p.sendMessage("Sign Created");

    }
     
  7. have you registered the event? BTW:
    use [*syntax=java][./syntax]
     
  8. Offline

    messageofdeath

    use this...
    PHP:
    @EventHandler
    public void onBP (BlockPlaceEvent e){
    Block b e.getBlock();
    if(
    b.getType().equals(Material.WALL_SIGN) || b.getType.equals(Material.SIGN_POST))
    {
    Player p e.getPlayer();
     
    p.sendMessage("Sign Created");
     
    }
    and for the sign changing use.
    PHP:
    @EventHandler
    public void onSignChange(SignChangeEvent event) {
    //do stuff
    }
     
    manniL likes this.
  9. Offline

    duckie33

    I think so this is what i have in my main file

    Code:java
    1. public void onEnable()
    2. {
    3. getServer().getPluginManager().registerEvents(new SignEvent(), this);
    4. }
    5.  
     
  10. Totally forgot that sign can be 3 different typs. sry ^^
     
  11. Offline

    messageofdeath

    it's only two ways "sign" is something i dont know about
     
    duckie33 likes this.
  12. Sign is the item in the inventory I thought ^^ or just the blank sign
     
    duckie33 likes this.
  13. Offline

    duckie33

    Thanks to both of you for helping me out :), any idea on the first question though?
     
  14. I'd suggest you to add this method in the listener:
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, plugin);

    initialized a variable like PLUGINNAME plugin;


    Second Question:

    Get the block via
    Code:java
    1.  
    2. Block test = block.getLocation().add(0, 1, 0).getBlock();
    3.  

    and then try to replace it with an redstonetorch for xxx seconds :D
     
  15. Offline

    duckie33

    Changed the op, new question :p
     
  16. Offline

    duckie33

    I did, i changed the the first post :D Also is there a reason your not sick and tired of me yet?
     
  17. It's possible.

    Code:java
    1.  
    2. public void onInteract (PlayerInteractEvent e){
    3. Action a = e.getAction();
    4. Player p = e.getPlayer();
    5. if(a.equals(Action.RIGHT_CLICK_BLOCK)){
    6. Block targetBlock = e.getClickedBlock();
    7. BlockState stateBlock = targetBlock.getState();
    8. if(targetBlock.getState() instanceof Sign){
    9. Sign sign = (Sign) stateBlock;
    10. if(sign.getLine(0).equals("WHAT IT SHOULD BE"))
    11. {
    12. p.sendMessage("YES MAN!");
    13.  


    Why I should? xD I like it to answer questions and help ppl ;)
     
    duckie33 likes this.
  18. Offline

    duckie33

    Its telling me BlockState, Action, and Sign can't be resolved to types. Do i have to import something?
     
  19. This things :p and maybe The event ^^

    and dont forget to use @EventHandler before and put this in your listener-class

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

    duckie33

    ohhhhhhhhh Oops :p

    Also mr Java expert what makes this code not work

    Code:java
    1.  
    2. Itemstack i = p.getItemInHand();
    3. if(a.equals(Action.RIGHT_CLICK_BLOCK) && i.equals(Item.PAPER))
    4.  



    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
    manniL likes this.
  21. Use i.getType().equals(Material.PAPER)
     
    duckie33 likes this.
  22. Offline

    duckie33

    Thanks! One last question i promise, is there somehow i can remove something from a players inventory within this
     
  23. player.getInventory().remove();
    There are specific way. You can define an ItemStack or whatever :)
     
Thread Status:
Not open for further replies.

Share This Page