Sign on Chest

Discussion in 'Plugin Development' started by catchaser9620, Aug 3, 2012.

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

    catchaser9620

    I was wondering if there was a way to attach a sign to a chest like in lockette?
     
  2. Offline

    azazad

    Listen for the PlayerInteractEvent, and see if the block being interacted with is a chest and the action was a right click. Then, place the sign depending on what BlockFace was clicked.
     
  3. Offline

    catchaser9620

    ok thx ill try that

    OK But how would i place the sign

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

    travja

    When you click the block, get the BlockFace that was clicked, and then use this code:
    Code:java
    1. event.getClickedBlock().getRelative(blockfacethatwasclicked).getState().setTypeID(Material.SIGN);
    2. event.getClickedBlock().getRelative(blockfacethatwasclicked).getState().update();
     
    Batman500 likes this.
  5. Offline

    catchaser9620

    I get an error from eclipse saying to change it to .setType woud that be ok?
     
  6. Offline

    travja

    oh, yeah, I said .setTypeID(Material.SIGN) instead of the signs ID. So that is good.
     
    Batman500 likes this.
  7. Offline

    catchaser9620

  8. Offline

    Ewe Loon

    dont forget to check the iteminhand for player clicking on the chest too
    once you have the clicked face you know which block is attached (next to) to that face
    set that blocks type using block.setType(Material.WALL_SIGN)

    then you will need to set the orentation of the sign using block.setData(Orentation)

    Note I have found when using setTypeID that sometimes the blocks cant be typecasted afterwards, whick is why i say use setType then setData rather than SetTypeIdAndData
     
  9. Offline

    catchaser9620

    Code:
    if(e.getClickedBlock().equals(Material.CHEST)) {
    Would this be right for checking if the clicked block is a chest?
     
  10. Offline

    travja

    I would do if(e.getClickedBlock().getType==Material.CHEST){
     
    Batman500 likes this.
  11. Offline

    catchaser9620

    ok thx
     
  12. Offline

    travja

    Good Luck! And have fun!
     
    Batman500 likes this.
  13. Offline

    catchaser9620

    ok heres my code: for somereason its not placing the sign:
    Code:
    @EventHandler
        public void onInteract(PlayerInteractEvent e, SignChangeEvent s) {
            if(e.getAction() == Action.LEFT_CLICK_BLOCK){
                if(e.getClickedBlock().getType() == Material.CHEST) {
                    if(e.getItem().getType() == Material.SIGN) {
                        for (BlockFace f : (new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}))
                            {
                            e.getClickedBlock().getRelative(f).getState().setType(Material.WALL_SIGN);
                            e.getClickedBlock().getRelative(f).getState().update();
                            s.setLine(0, ChatColor.WHITE + "BaseCommands");
                            s.setLine(1, ChatColor.DARK_AQUA + "ITEMBANK");
                            s.setLine(2, e.getPlayer().getName());
                            }   
                    }
                }
            }
        }
     
  14. Offline

    travja

    oh, I think I know... you can't get the state of a relative, so after .getRelative(f) add .getBlock() so .getRelative(f).getBlock().getState()

    Do it to both lines.
     
    Batman500 likes this.
  15. Offline

    catchaser9620

    it wont give me the .getBlock() option to put it in it gives me an error
     
  16. Offline

    Ewe Loon

    I would recommend using
    if(e.getClickedBlock().getTypeId==Material.CHEST.getId()) (i think i got it right as im typing here, not in eclipse)
    rather than getType
    this is because using getType would or could in future check more than just the typeid, including things like is it a double chest , or even inventory contents
     
  17. Offline

    travja

    What error does it give?
     
    Batman500 likes this.
  18. Offline

    catchaser9620

    The method getBlock() is undefined for the type Block
     
    Batman500 likes this.
  19. Offline

    travja

    K.... Right now all I can think is .getRelative(f).getLocation().getBlock().getState()....... a bit tedious unless you define variables like a blockstate variable...
     
    Batman500 likes this.
  20. Offline

    catchaser9620

    now it wont place the sign

    Code:
        @EventHandler
        public void onInteract(PlayerInteractEvent e, SignChangeEvent s) {
            if(e.getAction() == Action.LEFT_CLICK_BLOCK){
                if(e.getClickedBlock().getType() == Material.CHEST) {
                    if(e.getItem().getType() == Material.SIGN) {
                        for (BlockFace f : (new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}))
                            {
                            e.getClickedBlock().getRelative(f).getLocation().getBlock().getState().setType(Material.WALL_SIGN);
                            e.getClickedBlock().getRelative(f).getLocation().getBlock().getState().update();
                            s.setLine(0, ChatColor.WHITE + "BaseCommands");
                            s.setLine(1, ChatColor.DARK_AQUA + "ITEMBANK");
                            s.setLine(2, e.getPlayer().getName());
                            }   
                    }
                }
            }
        }
     
  21. Offline

    travja

    K... I am leaving soon... There is a tutorial by dinnerbone here:

    And that explains changing blocks.... Might need a little updating to the new Event System but it shouldn't be to hard... Good luck and Cya later!

    So Just use the block changing here and hopefully it works for your signs!
     
    Batman500 and catchaser9620 like this.
  22. Offline

    catchaser9620

    ok thx for the help!

    wait i found the error:
    15:59:31 [SEVERE] Wrong method arguments used for event type registered

    found it as my server was starting up

    the code that registers the event:

    Code:
    this.getServer().getPluginManager().registerEvents(new itembank(this), this);
    and i may very well switch to that after this for the 1.3.1 update

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

    travja

    Is the listener an embedded class in your main class or is it actually a whole other class?
     
    Batman500 likes this.
  24. Offline

    catchaser9620

    other class

    wait i thought you had to leave :confused:

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

    travja

    I'm leaving soon.... If it's another class put this before your onEnable and onDisable:
    public Listener variable = new Listener classname(this);

    Then when you register just use the variable name instead of making the class when you register, should fix it... if not just post, someone is always here!
     
    Batman500 likes this.
  26. Offline

    catchaser9620

    variable name?

     
  27. Offline

    travja

    public Listener variable = ....

    Basically, it's what you are calling your listener class in you main class.
     
    Batman500 likes this.
  28. Offline

    catchaser9620

    eclipse gave me an error so i had to get rid of the varriable part is that ok?

    EDIT: Nvm no its not ok
     
  29. Offline

    travja

    What error what it throwing?
     
  30. Offline

    catchaser9620

    Syntax error on token(s), misplaced construct(s)
     
Thread Status:
Not open for further replies.

Share This Page