Resource [1.8, 1.13] Custom Block Breaking | Change block hardness

Discussion in 'Spigot Plugin Development' started by Ytnoos, Mar 4, 2019.

  1. Your code is fetching classes and methods through reflection on each call. This is unnecessary upkeep, you could just fetch them once when the class is initialized. An even better solution is to steer clear of reflection. It does no good.
     
    • Agree Agree x 1
  2. I use Reflection because each version of CraftBukkit has a different package, so the code fits multiple versions. I know it's not the most efficient way in fact I'm working to use NMS without Reflection.

    P.S Good image, i love OverLord
     
    #22 TheDarkSword01, Mar 6, 2019
    Last edited: Mar 6, 2019
  3. Fixed an issue on step 5: Block wasn't recognized while being in a water block.
     
  4. In general I would recommend to use the Liskov Substitution principle and simply have a dependency on every NMS version. It may be a bit of a hassle to have a dependency on every NMS version, but you'll at least be able to check during compilation that the variables you access are working. You'll probably still need some reflection to access private variables for example, but if you're just doing simple stuff, you're best off in my opinion with a simple layer of abstraction on top of directly invoking NMS. It's a bit more work to maintain, but it's also more robust and less likely to break unexpectedly due to variable names from NMS changing and this not being caught at compilation time.
     
  5. You're absolutely right, I used Reflection just for convenience in fact right now I finished an example of plugins (CustomBlockBreakSystem) using the NMS abstraction.
    YTnoos if you want you can add it to the resources but I have not tested it yet, I'll let you know as soon as possible.

    https://github.com/TheDarkSword/CustomBlockBreakSystem
     
    • Like Like x 1
  6. When you will test it I will add it on the resources, btw nice work
     
  7. It works without problems, I have fixed something and added a class for the backward compatibility of the Materials.
     
  8. Added the GitHub repository.