[Discussion] Why are so many people using Bukkit. >>> getServer(). <<<

Discussion in 'Bukkit Discussion' started by FisheyLP, Jul 29, 2015.

?

Are you using Bukkit.getServer().someMethod ?

  1. Yes

    1 vote(s)
    12.5%
  2. No

    3 vote(s)
    37.5%
  3. Sometimes

    4 vote(s)
    50.0%
  4. Yes, but I will instead use the static methods from the Bukkit class directly now

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. I don't know why so many people make this "mistake", but Bukkit.getServer(). is so useless. All methods from the class Bukkit are static and access the methods directly from .getServer().
    It is just a waste of time (so many seconds lost in your life xD).

    Example code directly copied from decompiled craftbukkit's Bukkit.java class:
    Code:
    public static PluginManager getPluginManager()
    {
       return server.getPluginManager();
    }
    So instead of using
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(..., ...);
    you can just use
    Code:
    Bukkit.getPluginManager().registerEvents(..., ...);
    which is pretty much the SAME.

    Or does anyone see any advantages of using Bukkit.getServer(). ? I don't see any
     
  2. I foggily remember that getPluginManager had been added later than getServer, such could explain why it is found in so many places, or why people got used to. In addition Bukkit.getServer()... is more similar to the use within the Plugin classes, which would be plugin.getServer().getPluginManager().

    Check the blame view, months (!!! :p) between: https://github.com/Bukkit/Bukkit/blame/master/src/main/java/org/bukkit/Bukkit.java

    Concerning what it boils down to, it might just be about the same byte code. With code completion it might be less than a second.
     
  3. Offline

    timtower Administrator Administrator Moderator

    @FisheyLP Some people don't use the static reference at all. I personally use plugin.getServer().<whatever I might need here>
    I think that it is mostly a habit thing
     
  4. I always use getServer for methods like getPluginManager and even methods I know Bukkit has. I do it purely out of habit and prefer doing it like that. I've been doing it for years, it's something I just naturally do.
     
  5. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Bukkit.getServer() is for if you need the Server instance.

    The bigger question is why do folks use the Bukkit class static methods from inside classes where the server is already available?
     
    bwfcwalshy and timtower like this.
  6. Offline

    blablubbabc

    Consistency maybe, if you use the static Bukkit.xxx shortcuts at a lot of other places already.
     
  7. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    That only reveals further problems in the lack of reference passing in your code.
     
    timtower likes this.
  8. Offline

    blablubbabc

    Which turns the question into the classic one: 'Using Bukkit.xxx shortcuts vs passing references around' aka 'Why use Bukkit.xxx shortcuts at all?'.
     
  9. It accesses all methods from Bukkit.getServer() directly (singleton pattern) and it's shorter to write
     
  10. I assume nowadays just in time compilers might kill off the difference :p

    They're shorter :p - for more complex plugins, some random class will probably provide functionality which needs testing for plugins or other stuff that can be accessed with writing less letters using static Bukkit methods.

    In my opinion it's not the most important thing to write the least amount of letters, e.g. people use IDE features for code completion very often to duplicate all sorts of API calls (getBlock().getLocation().getWorld().getBlockAt(...).getLocation()... multiple times for the same location in the same line) - if you distrust just in time compilation, then pull down those things fisrt!
     
Thread Status:
Not open for further replies.

Share This Page