Register - Now accepting all Payment Methods (Economy API) [Stable]

Discussion in 'Resources' started by Nijikokun, May 10, 2011.

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

    Don Redhorse

    you need to use register as plugin name

    yeah I know about the loading order via depend... but that doesn't help if Register isn't there, and as I only need the information IF it is available I need to check if I can use the method by checking if the plugin is there.

    like I said... there is a little bit of a beginners guide missing with register... and the "Examples / Usages" doesn't really help as it is only for full blood java developers :D


    and before you ask why I need the balance.. next to the ItemsAPI I'm writing I have a "little" project with will grab information from all over and display it to the player / admin and make it accessible by other means..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  2. Offline

    RPGWorld

    Ooh,you're making the items api! Awesome!
    Well,if Register isn't there,just disable the plugin and tell them to get Register >.>
     
  3. Offline

    Don Redhorse

    hehe... well I will not disable the plugin.. I will just disable the register integration.. that's why I need the boolean value.. I can figure that out... I just need to figure out what some people mean with the code they write :)
     
  4. Offline

    okami35

    Do you have an example for Setting Register up with a Server Listener?
     
  5. Offline

    staxx6

  6. Offline

    okami35

    up, nobody has an exemple?
     
  7. Offline

    Isabaellchen

  8. Offline

    undeadmach1ne

    ^that is pretty funny :p

    ok so i just got around to trying 1.5 and it seems to be working fine right now with a very basic implementation during entitydeath (if killer = player)
    Code:
    Methods.getMethod().getAccount(killer).add((double) event.getDroppedExp());
    this seems to work fine upon initial testing with ico5...but i am a noob so everything is kinda mysterious still lol...is there anything i should do to ensure that my plugin is fully compatible with other setups? i literally just got this working, so im going to do some testing now and probably (hopefully) answer that question for myself, but i figure ill ask just to be safe (cant trust a noob lol) :) thanks for any help...
     
  9. Offline

    _ralts

    You'll need to check if there actually is an economy plugin...

    Code:
    Method method = Methods.getMethod();
    if(method != null) {
        // Do stuff
    } else {
        // No economy! Oh noes!
    }
    
    You can use Methods.hasMethod(), but I don't like that because then there's a small chance the Method will disappear in between when you call that and when you call getMethod()
     
    undeadmach1ne likes this.
  10. Offline

    okami35

    so, we don't have to use a ServerListener?
     
  11. Offline

    undeadmach1ne

    thanks :)
     
  12. Offline

    okami35

    I have tried this code:

    Code:
    public class eco extends JavaPlugin{
    	public static Method method = Methods.getMethod();
    	public static Logger log = Logger.getLogger("Minecraft");
    
    	@Override
    	public void onDisable() {
    		// TODO Auto-generated method stub
    	}
    
    	@Override
    	public void onEnable() {
    		// TODO Auto-generated method stub
    		log.info("[ECO]plugin charge");
    	}
    
    }
    
    And i haven't errors with eclipse and i added register.jar as an external jar.
    But when i run my server, i have a ClassNotfoundException, do you know where is the problem?

    Thank you
     
  13. Offline

    desht

    I wouldn't try to run Methods.getMethod() from your plugin constructor - too early. Register probably isn't loaded yet. Do it in onEnable(), and be sure to check the return value for null.
     
  14. Offline

    KrisEike

  15. Offline

    okami35

    Always the same problem, classNotFoundException
    I just added the register.jar in my project as an external jar, maybe i should do someting else?
    thank you
     
  16. Offline

    okami35

    nobody has an example or a tutorial?
    I am desperate
     
  17. Offline

    Codisimus

    I could proly post how I use this later but I don't use it as a separate jar
     
  18. Offline

    Erbros

    Thanks, this could fix the problem some of my users have had selecting iConomy over essentials eco :) Testing it.
     
  19. Offline

    desht

    OK, my ScrollingMenuSign plugin uses Register as an external JAR. You can browse the code at https://github.com/desht/ScrollingMenuSign, in particular the main ScrollingMenuSign.java and parser/Costs.java classes. A few notes:
    • Add a dependency on Register (hard or soft, depending on your plugin needs) in your plugin.yml
    • setupEconomy() in ScrollingMenuSign.java does the initial detection, and if a suitable method is found, records that in my plugin instance via the setEconomy() method. Other classes in my plugin can then get the economy method via getEconomy(). See chargePlayer() in parser/Cost.java for an example of that.
    • One little gotcha that I hit was that if I called setupEconomy() direct from my onEnable(), it didn't always detect an economy plugin (sometimes, but not reliably). My server log showed that Register didn't find iConomy until after SMS had finished enabling - which is weird. So I deferred setupEconomy() via a Scheduler.scheduleSyncDelayedTask(), which seems to have solved the problem. I don't know if it's the "best" way, but it works.
     
    Don Redhorse likes this.
  20. Very nice plugin!

    But I had to spent much time to get it working, maybe a noob guide would be useful ;)
     
  21. Offline

    okami35

    thank you for your sources, i have tried this:
    Code:
    PluginManager pm = getServer().getPluginManager();
            Plugin p = pm.getPlugin("Register");
            if (p != null && p.isEnabled()) {
                Methods.setMethod(pm);
                if (Methods.getMethod() != null) {
                    log.info("Register ok");
                } else {
                    log.info("no Economy plugin");
                }
            } else {
                log.info("register not loaded");
            }
        }
    But i have "register not loaded", but in bukkit, register is loaded...

    Thank you

    Thank you very much
     
  22. Offline

    Don Redhorse

    I put up a server listener for it... I have to test it though..

    looks like it works... it spams a little thoughs.. I have 2 lines for the loggin..
     
  23. Offline

    desht

    Yeah, that may be the best way to do it.
     
  24. Offline

    okami35

    And do you know why register is not recognized by my plugin?
     
  25. Offline

    Don Redhorse

    try this as an extra class... it might be that register is not already loaded when you load your plugin.. there are bugs with dependencies..

    I know the code isn't good... I'm refactoring it like hell atm...

    plugin.useRegister = true;

    is used in the main class to use register or not... otherwise you will get npe if you call a register method and the plugin isn't there.

    I think my github is up to date with this working code..

    Code:
    public class server extends ServerListener {
        private DeathTpPlus plugin;
        public static Method economy = null;
     
        public server(DeathTpPlus plugin) {
            this.plugin = plugin;
    
        }
    
        public static void setEconomy(Method economy) {
            server.economy = economy;
        }
    
        public static Method getEconomy() {
            return economy;
        }
    
        @Override
        public void onPluginDisable(PluginDisableEvent event) {
            PluginManager pm = plugin.getServer().getPluginManager();
            Plugin checkRegister = pm.getPlugin("Register");
            if ((checkRegister == null) && plugin.useRegister) {
                Methods.setMethod(pm);
                if (Methods.getMethod() == null)
                {
                    plugin.useRegister = false;
                    plugin.log.info(plugin.logName +"un-hooked from Register.");
                    plugin.log.info(plugin.logName +"as Register was unloaded / disabled.");
                }
            }
     
        }
    
        @Override
        public void onPluginEnable(PluginEnableEvent event) {
    
            PluginManager pm = plugin.getServer().getPluginManager();
            Plugin checkRegister = pm.getPlugin("Register");
            if (checkRegister != null) {
                Methods.setMethod(pm);
                if (Methods.getMethod() != null)
                {
                    setEconomy(Methods.getMethod());
                    plugin.log.info(plugin.logName +"Economy method found: "+ getEconomy().getName()+ " v "+ getEconomy().getVersion());
                    plugin.useRegister = true;
    
                } else {
                    plugin.log.warning(plugin.logName +"Register detected but no economy plugin found!");
                    plugin.useRegister = false;
                }
            } else {
                plugin.log.info(plugin.logName + "Register not detected, will attach later.");
            }
        }
    }
     
  26. Offline

    okami35

    Thank you very much, it works perfectly.
    Thank you
     
  27. Offline

    NeoSilky

    What have i broken this time? :(
    Code:
    2011-10-16 09:31:58 [SEVERE] Error occurred while enabling CompanyMiner v0.1 (Is it up to date?): com/nijikokun/register/payment/Methods
    java.lang.NoClassDefFoundError: com/nijikokun/register/payment/Methods
    	at me.neosilky.companyminer.CompanyMiner.onEnable(CompanyMiner.java:50)
    	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:170)
    	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:957)
    	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:171)
    	at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:154)
    	at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:297)
    	at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:284)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:152)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    Caused by: java.lang.ClassNotFoundException: com.nijikokun.register.payment.Methods
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:36)
    	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:24)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	... 11 more
    
    Probably terrible wrong code, but here's some of it:
    Code:
    	private Method economy; //under javaplugin
    boolean economyplugin = false; //just a boolean i use, dont really need it.
    		this.economy = Methods.getMethod(); //under onEnable
    
    		if(economy != null) {
    		    this.logger.info("[CompanyMiner] Economy Plugin Found!");
    		    economyplugin = true;
    		} else {
    		    this.logger.info("[CompanyMiner] Economy Plugin Not Found! Default to built in credits!");
    		} //under the last one.
    
    Need anything else, just ask. I didn't know what to do with the plugin.yml, and i added it as a library. Please help ;)

    EDIT: checked the Register by removing all references inn the code, its Register :(
     
  28. Offline

    5lood

    I was like....DUUHHH.... while reading so is this plug-in like the /register <Password> thing or what?
     
  29. Offline

    NeoSilky

    No, this is not a plugin. It is a Library for plugin developers :p
     
  30. Offline

    Pavilliox

    No idea how to use this. Noob guide please.
     
Thread Status:
Not open for further replies.

Share This Page