[Class] Holograms in 1.8+

Discussion in 'Spigot Plugin Development' started by Janhektor, Dec 23, 2014.

Thread Status:
Not open for further replies.
  1. Then interface is better... Because when you're coding... you're always doing... And you don't care about the implementation or even if it gets done.

    Consider a configuration option for server owners & admins to turn holograms on/off... Then you can have a HologramsOn implementation and a HologramsOff implementation... And you don't have clutter your code with conditionals.

    https://github.com/Europia79/Demolition/tree/master/src/main/java/mc/euro/demolition/holograms
     
  2. sothatsit

    Patron

    There is absolutely no need for it. Not in this instance. Interfaces are good in some instances. But in this case it is a waste of space.
     
  3. I agree with you, but the interface will be useful in future versions.
    Currently I'm working on another implementation (in addition to DefaultHoloAPI.java) for these interface.
    In this case the interface is used to define the structure of my implementations.

    Is now on my list - update will come soon.

    Okay, I'll try to improve that.
    Changing & Moving is a good idea, I'm going to try it.
     
  4. sothatsit

    Patron

    If you had multiple hologram implementations then yes, it would be preferable. Just not necessary right now.
     
  5. Which code looks better to you:

    #1.
    Code (Java):
    if (this.plugin.getConfig().getBoolean("HologramsOn")) {
        api.display(player);
    }
    #2.
    Code (Java):
    api.display(player);
    They both do the same thing. Just in different ways. For #1. anytime you wanna use Holograms, you have to first check if the server has configured them to be on. #2. uses a polymorphic solution where the display() behavior changes depending on the implementation (in this case, an ON or OFF implementation that can be toggled at runtime).
     
  6. sothatsit

    Patron

    And you cant just change the implementation yourself because....? Still no need for an interface. Just extend the class or edit the class. Copying the hologram class just to add a boolean check is pretty stupid. Extending it is the best solution.
     
  7. Proxy Guapaaaa <3
     
  8. Examples #1 & #2 are use-case examples... those pieces of code would normally be run inside commands or events... NOT inside the hologram class. WOW. So many plugins out there have all kinds of configuration options to make their plugins customizable, is it so hard to conceive of an option to turn holograms on & off ?

    I don't think you understood the question (you didn't answer it, but i should have been more clear).

    Which command/event code looks better to you ? (Hint: they both do the exact same thing)
    #1.
    Code (Text):
    if (this.plugin.getConfig().getBoolean("HologramsOn")) {
        api.display(player);
    }
    #2.
    Code (Text):
    api.display(player);
     
  9. sothatsit

    Patron

    Obviously the second one. But an interface is not the best way to achieve the same thing. A better way to achieve it is to do something like

    Code (Text):
    class ConfigHologram extends HoloAPI {
        @Override
        public void display(Player player) {
            if(YourPlugin.getInstance().isHologramsEnabled()) {
                super.display(player);
            }
        }
    }
    that way your not copying the exact same code into 2 classes which implement the same interface.
     
    • Creative Creative x 1
  10. That's a nice trick. Very clean. A good alternative.
     
  11. What's missing is that you can change the Hologram.

    That would be nice because I program a stats hologram
     
  12. You are the corrector always LOL. I see you always hahaha DarkSeraWiki
     
  13. 1st: Store the result of these Class#getMethod calls static!
    2nd: As said before, armorstands despawn after a certain distance iff you have not turned it off (There is a method with a "useful"/deobfuscated name for it, like DespawnWhenFarAway or so)
     
Thread Status:
Not open for further replies.