Directional for Sign not working

Discussion in 'Plugin Development' started by Alias_Me, Jan 19, 2019.

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

    Alias_Me

    So I am writing a method for finding the direction a sign is facing (and doing something else but thats irrelevant) and this is what I got so far (Ignore the File parameter):

    Code:Java
    1.  
    2. public void writeTeleportLocation(File file, Sign sign) {
    3. Directional direction = (Directional) sign.getBlockData();
    4. System.out.println(direction);
    5. }
    6.  


    Which throws a ClassCastException: org.bukkit.craftbukkit.v1_13_R2.block.impl.CraftFloorSign cannot be cast to org.bukkit.block.data.Directional

    I tried just using getData() as advised in other threads, which gave me similar Exception, and since it apparently cant be casted to org.bukkit.block.data.Directional I figured .getBlockData(), which is supposed to return BlockData, would work, but apparently not.

    I also tried casting the sign to a block before giving the sign as a Block to the method, but that didnt work either.

    In case its relevant, heres the full class:
    https://pastebin.com/UB6AYxyJ
     
  2. I assume that your sign is a org.bukkit.block.Sign. This class inherits from BlockState thats why you get an error when trying to cast it to directional. If you get your sign as a org.bukkit.block.data.type.Sign (using block.getBlockData()), you can access the method sign.getRotation();
     
  3. Offline

    Alias_Me

    @DerDonut Wait, so what would I have to cast the Block to? Because no matter if I try to make it Material, Block or Sign I cant get a .getRotation() method.

    I dont like spoonfed code, but if the sign was accessible by event.getBlock(), what would I have to do to be able to use a getRotation() method?
     
  4. Code:Java
    1. Block b = //somehow get the block
    2. Sign s = (Sign) b.getBlockData();
    3. s.getRotation();


    import 'org.bukkit.block.data.type.Sign' instead of 'org.bukkit.block.Sign'
     
  5. Offline

    Alias_Me

    @DerDonut That works, but I couldnt use methods like .getWorld() on the sign anymore, turns out I have to re-specify what type of sign I want during casting.
     
  6. Yeah
    you probably need 2 different sign objects for this. Idk maybe there is also a way to get the rotation from the block.sign I just didn't found it yet. I don't know what you want do do but you could also give the method the block object, then you can use methods to get the position etc and also get the rotation of the sign
     
Thread Status:
Not open for further replies.

Share This Page