Solved Canceling fall will not work, no matter how hard I try

Discussion in 'Plugin Development' started by sgavster, Nov 12, 2013.

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

    1Rogue


    Even then passing the instance properly is better.
     
  2. Offline

    LazyLemons

    Code:java
    1. Factions.get().method(...);
    >
    Code:java
    1. ((Factions)Bukkit.getPluginManager().getPlugin("Factions")).method(...)
     
  3. Offline

    1Rogue


    Code:java
    1. public class ADumbArgument {
    2.  
    3. private final Factions factions;
    4.  
    5. public ADumbArgument() {
    6. this.factions = (Factions) Bukkit.getPluginManager().getPlugin("Factions");
    7. }
    8.  
    9. // wow. such instance.
    10.  
    11. }
     
  4. Offline

    LazyLemons

    Either way, you can't be completely static free, your method still has the Bukkit.getPluginManager() call. Though I do agree with your class name, this is a pointless argument...
     
  5. Offline

    xize

    for the people static != wrong, if you use it correctly as globalized objects and not for anything else you are doing a good thing, but if you instance every little object like myType type = new MyType(); (including things which are global) you are doing very bad things and make the garbage collector over heap thats why globalizing only the objects which need to be accessed by more classes than only one a must for static.

    in this case for the arraylists and such because it contains all in the same class you shouldn't use static unless you want access it by other classes.

    Also I don't understand why people are using myPlugin.getInstance()?, this is not the final plugin object and is part of the reflection api not checked though, what you need to do is make a global field which returns your plugin instance in your main this might not solve the problem though.

    main class
    Code:
    public class myPlugin extends JavaPlugin {
          private static myPlugin pl;
          public void onEnable() {
               pl = this;
          }
    
    public static myPlugin getPlugin(){
    return pl;
    }
    }
    
    Reason why I use static here is because I hate constructors they can do alot but a overload on constructors is bad to.
    plus this is also good because you won't instance every time a new instance of this what ive learned is try as much to avoid getting new instances because once they can marked as unused and got stored in gc thats why I choose static only on objects which get used more than once in more classes.
     
  6. Offline

    sgavster

  7. Offline

    maxben34

    I feel like a simple solution has been avoided due to fighting over how to use static methods. It isn't helping anybody out here by fighting over the use of static.
     
  8. Offline

    xTrollxDudex

    xize
    Constructors don't pass a new instance of the main class, just a reference of it.
    sgavster
    Print out the names in the list. What I think is happening is you are registering your listener and your command in different instances of the same class:
    PHP:
    pm.registerEvents(new Something(this), this);
    getCommand(...).setExecutor(new Something(this))
    Try using
    PHP:
    Something s = new Something(this);
    p.m.registerEvents(sthis);
    getCommand(...).setExecutor(s);
     
    sgavster likes this.
  9. Offline

    sgavster

Thread Status:
Not open for further replies.

Share This Page