Solved How to get .saveResource from main class with extend JavaPlugin on another class?

Discussion in 'Plugin Development' started by augustas656, Sep 10, 2014.

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

    augustas656

    Literally what the question says...

    Edit:
    Solution:
    1.) Define Plugin plugin in class
    2.) Set plugin to this (class with extend JavaPlugin)
    3.) Make method to return plugin, and use method in other classes
     
  2. Offline

    Zarkopafilis

    Make a class to hold your data, make a Plugin variable that is public and static. Pass the instance on the onEnable method
    Access it
     
  3. Offline

    augustas656

    That's what I did, maybe I wrote it hard to understand, but reading what you said that's practically what I did... I just wasn't writing about classes
     
  4. Offline

    fireblast709

    AdamQpzm likes this.
  5. Offline

    DusRonald

    fireblast709 Does a own getPlugin() method work at this?

    This:
    Code:java
    1. public void getPlugin(Plugin p){
    2. return Bukkit.getPlugin(p.toString());
    3. }
     
  6. Offline

    BillyGalbreath

    MyPlugin.java
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2. public onEnable() {
    3. new SomeOtherClass(this);
    4. }
    5. }


    SomeOtherClass.java
    Code:java
    1. public class SomeOtherClass {
    2. Plugin myPlugin;
    3.  
    4. public SomeOtherClass(Plugin plugin) {
    5. this.plugin = plugin;
    6. }
    7.  
    8. public void doSomeThingMethod() {
    9. // yadda yadda
    10. myPlugin.saveResource(String, boolean);
    11. // yadda yadda
    12. }
    13. }
     
  7. Offline

    fireblast709

    DusRonald you try to get the Plugin from the Plugin itself, so that would never work :p. That aside, you would need to use getName().
     
  8. Offline

    DusRonald

    fireblast709 And does this working?
    Code:java
    1. public Plugin getPlugin(String name){
    2. return Bukkit.getPluginManager.getPlugin(name);
    3. }


    If not, can you post a code that works?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  9. DusRonald With correct parentheses applied, that'll work.
     
  10. Offline

    BillyGalbreath

    Why would you get your own plugin's instance that way? The OP states you want to get the plugin's instance in other classes... This is a very "round-about" way of doing it, and completely unnecessary. See my previous post on how to pass your plugin's instance to other classes.
     
  11. Offline

    Zarkopafilis

    Domain classes should use static AFAIK
     
Thread Status:
Not open for further replies.

Share This Page