Get UserMap in Essentials

Discussion in 'Plugin Development' started by Lactem, Jan 15, 2014.

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

    Lactem

    Did you ever find out how to get that UserMap?
     
  2. Offline

    xTrollxDudex

    Lactem
    ...............................................
     
  3. Offline

    Lactem

    Yes....? Anyway, if anyone knows how to get Essential's instance of IEssentials (named ess), please tell me. I'm currently looking through their code to try to figure it out.

    Edit: I can't really do anything kit-wise without getting that variable called "ess."
     
  4. Offline

    xTrollxDudex

    This is a YEAR OLD thread, start a new one instead of necrobumping an old thread.

    Besides that, it depends on what you need it for.
     
  5. Offline

    Lactem

    xTrollxDudex
    I need it to give a kit.


    final List<String> items = Kit.getItems(ess, customKits.getUser(p.getName()), args[1], ess.getSettings().getKit(args[1]));

    This is not possible due to the fact that I can't get that variable "ess," which is because it does not have any getter, only a setter. It's set when Essentials first loads - https://github.com/essentials/Essen...s/src/com/earth2me/essentials/Essentials.java, and then there's no way (at least that I know of) to get it.
     
  6. Offline

    ZephireNZ

    Agreed. This was back when I really had little idea what I was doing. Chances are if you're tripping up on this, you may want to watch some tutorials on static references (might I recommend thenewboston).
     
  7. Offline

    Lactem

    ZephireNZ
    Uh, no. There's no Essentials.getInstance() or any method like that. I ain't trippin' bro. ;)
     
  8. Offline

    ZephireNZ

    Because I might as well:
    You'll want to use
    Code:java
    1. Bukkit.getPluginLoader().getPlugin("Essentials")
    . This will give you either null, or the main Essentials instance as a JavaPlugin. Make sure you check it's actually an instanceof Essentials, and it's not null. This will give you access to the Essentials base plugin class, from which you should have access to most things.
     
  9. Offline

    Lactem

    ZephireNZ
    Yes, yes. I've done this and casted Essentials, but my problem is that there's no way to GET that IEssentials variable that's already set. It would be simple if they had a getEss() method, but they don't, and so that's my problem.
     
  10. Offline

    ZephireNZ

    Hm, in that case I'd take it up with them. You'll likely get a quicker answer that way. Try talking to them on IRC (irc.esper.net, #essentials).
     
  11. Offline

    Lactem

    ZephireNZ
    Yeah I probably have to do that.
     
  12. Offline

    xTrollxDudex

    Lactem
    You would actually cast that to IEssentials, the class implements that.

    Edit: Whoops, don't do that uet.

    Edit:
    PHP:
    JavaPlugin plugin = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
    Class<?classInstance plugin.getClassLoader().findClass("com.earth2me.essentials.Essentials");
    Class<
    ?> iEssentialsInstance = classInstance.asSubclass(IEssentials.class);
    IEssentials ess = (IEssentials) iEssentialsInstance.newInstance();
    Edit:
    PHP:
    JavaPlugin plugin = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
    JavaPluginLoader loader = (JavaPluginLoader) plugin.getPluginLoader();

    Field f = loader.getClass().getDeclaredField("loaders");
    f.setAccessible(true);
    Map<String, PluginClassLoader> map = (Map) f.get(loader);

    PluginClassLoader load = map.get("Essentials");
    Field fd = load.getClass().getDeclaredField("classes");
    fd.setAccessible(true);
    Map<String, Class<?>> clses = (Mapfd.get(load);

    Class<
    ?> finalClass;
    for(Class<?clses.valueSet()) {
        if(
    c.getSimpleName().equals("Essentials")) {
            
    finalClass c.asSubclass(IEssentials.class);
        }
    }

    IEssentials ess finalClass.newInstance();
     
  13. xTrollxDudex Why use reflection if it can be done much easier? Here is some code directly copied from EssentialsChat:
    Code:
    final PluginManager pluginManager = getServer().getPluginManager();
    final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials");
     
    if (!ess.isEnabled())
    {
        this.setEnabled(false);
        return;
    }
     
  14. Offline

    xTrollxDudex

    CaptainBern
    Congrats on DBO staff!

    Anyways, I was thinking that getPlugin returns the generic plugin "object of the plugin" if you know what I'm saying:
    Then again, I always make sure to doubt my own answer.
     
    CaptainBern likes this.
  15. xTrollxDudex Thank you very much :)
    About the "Object of the plugin", indeed, it stores the plugin object.
     
  16. Offline

    xTrollxDudex

  17. xTrollxDudex Why would you need that if casting to IEssentials works perfect?

    Edit: You can perfectly cast the Plugin object to IEssentials, add this code to a plugin:
    Code:java
    1. System.out.print(Bukkit.getPluginManager().getPlugin("Essentials").getClass().getName());

    The expected output will be: com.earth2me.essentials.Essentials.
    I'm sorry I can't really explain it any better :/
     
    xTrollxDudex likes this.
  18. Offline

    lycano

  19. Offline

    Necrodoom

    Moved to new thread. Please do not necropost on threads.
     
Thread Status:
Not open for further replies.

Share This Page