The method getAttachedFace() is undefined for the type MaterialData

Discussion in 'Plugin Development' started by 123isme1, Aug 23, 2014.

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

    123isme1

    I have look for numerous hours on google, and come up with nothing. I simply want to find out if a sign is on a chest. After all my googling I have come up with the following:
    Code:java
    1. if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN){
    2. Sign sign = (Sign) b.getState();
    3. if(sign.getBlock().getRelative(sign.getData().getAttachedFace()).equals(Material.CHEST)){
    4. //do code blah blah blah
    5. }

    It simply comes up with
    Code:
    The method getAttachedFace() is undefined for the type MaterialData
    Note: I am importing the Block, not Material, and the event is SignChangeEvent

    EDIT: Whole class so far:
    Code:java
    1. package com.mc123isme1.post;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Sign;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.SignChangeEvent;
    12. import org.bukkit.material.Attachable;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener{
    16. public void onEnable(){
    17. Bukkit.getPluginManager().registerEvents(this, this);
    18. }
    19. @EventHandler
    20. public void onSignPost(SignChangeEvent e){
    21. Player p = e.getPlayer();
    22. Block b = e.getBlock();
    23.  
    24. if(e.getLine(0).equalsIgnoreCase("[post]")){
    25. if(e.getLine(1).equalsIgnoreCase(p.getName())){
    26. if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) {
    27. Sign sign = (Sign) b.getState();
    28. if(sign.getBlock().getRelative(sign.getData().getAttachedFace()).equals(Material.CHEST)){
    29. e.setLine(0, "[" + ChatColor.GREEN + "Post" + ChatColor.RESET + "]");
    30. }
    31. }
    32. }
    33. }
    34. }
    35. }
     
  2. Offline

    Zupsub

    Cast sign.getData() to org.bukkit.material.Sign:

    ((org.bukkit.material.Sign) sign.getData()).getAttachedFace()
     
  3. Offline

    123isme1

    Zupsub hmm, no errors, but it just doesn't work
     
  4. Offline

    Zupsub

    Does it recognize the right block? Which checks it instead? Btw. Please update your posted code to the current one then.
     
  5. Offline

    123isme1

    Here it is Zupsub
    Code:java
    1. package com.mc123isme1.post;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.SignChangeEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener{
    15. public void onEnable(){
    16. Bukkit.getPluginManager().registerEvents(this, this);
    17. }
    18. @EventHandler
    19. public void onSignPost(SignChangeEvent e){
    20. Player p = e.getPlayer();
    21. Block b = e.getBlock();
    22.  
    23. if(e.getLine(0).equalsIgnoreCase("[post]")){
    24. if(e.getLine(1).equalsIgnoreCase(p.getName())){
    25. if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) {
    26. Sign sign = (Sign) b.getState();
    27. if(sign.getBlock().getRelative(((org.bukkit.material.Sign) sign.getData()).getAttachedFace()).equals(Material.CHEST)){
    28. e.setLine(0, "[" + ChatColor.GREEN + "Post" + ChatColor.RESET + "]");
    29. }
    30. }
    31. }
    32. }
    33. }
    34. }


    Zupsub just a second, it seems that I am compiling and testing on different versions

    Zupsub Tested on same versions, still doesn't work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    SpaceManiac

    Your code won't work and shouldn't be compiling at all. You need to check if the block is a sign and if so perform the cast to org.bukkit.block.Sign *before* you try to check what lines the sign contains.
     
  7. Offline

    Zupsub

     
  8. Offline

    123isme1

    eh nvm, I sortof gave up on the plugin, ran into a dead end on another part.
     
Thread Status:
Not open for further replies.

Share This Page