Solved NoSuchMethodError: getTargetBlock

Discussion in 'Plugin Development' started by 0ct0berBkkitPlgins, Sep 27, 2015.

Thread Status:
Not open for further replies.
  1. I'm getting this error when I try and use getTargetBlock. I am using the correct format, but as the error says, the method does not exist (I know the deprecated one, I'm using the Set<Material> one). Iv'e also tried this with players and have gotten a similar issue. Can someone please help?

    java.lang.NoSuchMethodError: org.bukkit.entity.LivingEntity.getTargetBlock
     
  2. goosebumps O~o
     
  3. Offline

    Lolmewn

    Please show your code, tell us against which version of bukkit you are building and which version of bukkit you're using for testing.
     
  4. @Lolmewn Bukkit 1.8 on Bukkit 1.8.
    Code:
    Block b = ((LivingEntity)p).getTargetBlock((Set<Material>)null, 5);
    I have also tried this without the LivingEntity cast. I found somewhere it said this would help, but really all it did was change the error message from entity.Player to entity.LivingEntity.
     
  5. Offline

    Lolmewn

  6. @Lolmewn That is what I had seen used before. I also created the set via this previously:
    Code:
    Set<Material> transparent = null;
    I was told on the Javadoc that setting it to null would make it only look through air.

    It doesn't say anything like incorrect arguments or something, and it didn't show any compilation errors... it specifically said the method does not exist.
     
  7. Offline

    Lolmewn

    @0ct0berBkkitPlgins In that case, it would appear that a LivingEntity does not support getTargetBlock (although I thought it did - maybe that's players only though?)
     
  8. @Lolmewn No, I tried it with players :l thats the whole reason I tried LivingEntity, because players didn't work and changing it fixed it for someone. I know casting something to null isn't good... in fact I never do that. I just saw it helped someone fix the same issue in the past on an old threat (I forget which one). Problem is the error persists, even if I change the code to be a new set or set = null.

    I also tried getLineOfSight(transparent, 5).get(0) and found that this didn't work either. Please help... I don't know what the issue is. Iv'e seen some people mentioning the error when they use plugins, so I think an update broke this

    Edit: This is a stupid bug. I was using Bukkit 1.8 for both testing and compiling and got no compilation errors. Thankfully if you use "magic" values and suppress the deprecation, it works.
     
    Last edited: Sep 28, 2015
  9. Offline

    Tecno_Wizard

    @0ct0berBkkitPlgins, hence the deprecation.

    Magic just means that the value is not clearly defined without looking over bukkit's code.
     
  10. @Tecno_Wizard I've used it before... I know what it means. I'm just annoyed that it doesn't work with current block types.
     
  11. Offline

    Tecno_Wizard

    @0ct0berBkkitPlgins,

    "A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists... Deprecated methods are often not updated once they have been annotated as such"

    By definition the newer ones won't work. There's no reason to be upset over it.
     
  12. @Tecno_Wizard The quotation you provided doesn't say anywhere that new methods won't work. There are plenty of new methods or not-deprecated methods that work perfectly fine, and in most cases you should expect a method to exist if it is provided. What you quoted is simply a fact about deprecation, which we all already know, and has little to do with my frustration and is not a reason for me to not be annoyed.
     
  13. Offline

    Tecno_Wizard

Thread Status:
Not open for further replies.

Share This Page