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

    halvors

    @Nijikokun
    I can't get this work. I get this error on every line that uses your Register api:

    If you need to look in my code it's here: https://github.com/halvors/Sneak

    Code:
    if ((economy.hasAccount(target.getName())) && (economy.hasAccount(player.getName()))) {
                                int delay = 10 * 1000;
    
                                if (delays.containsKey(player.getName())) {
                                    if ((System.currentTimeMillis() - delays.get(player.getName())) < delay) {
                                        player.sendMessage(ChatColor.RED + "You can't sneak " + target.getName() + " so often.");
    
                                        return;
                                    }
                                }
    
                                double amount = economy.getAccount(target.getName()).balance() / 100 * 10.0;
    
                                if (economy.getAccount(target.getName()).hasEnough(amount)) {
                                    economy.getAccount(target.getName()).subtract(amount);
                                    economy.getAccount(player.getName()).add(amount);
    
                                    player.sendMessage(ChatColor.GREEN + "You sneaked " + target.getName() + " and got " + economy.format(amount) + ".");
                                    target.sendMessage(ChatColor.RED + "You where sneaked by " + player.getName() + " and lost " + economy.format(amount) + ".");
    
                                    delays.put(player.getName(), System.currentTimeMillis());
                                } else {
                                    player.sendMessage(ChatColor.RED + target.getName() + " have no money");
                                }
    
     
  2. Offline

    AOD_Batman

    I think I may have noticed a logic problem here. If for example my plugin is the last one loaded and the economy plugin was already loaded prior. Then there is no way, giving the example that you've supplied, that the public "Method" object in my plugin class will ever get set. Thus in the constructor method of my Server Listener I have added the following:

    Code:
            PluginManager pm = _plugin.getServer().getPluginManager();
    
    
            if (_methods != null && !_methods.hasMethod()) {
                if (_methods.setMethod(pm.getPlugin("iConomy"))) {
                    _plugin.method = _methods.getMethod();
                }
                else if (_methods.setMethod(pm.getPlugin("BOSEconomy"))) {
                    _plugin.method = _methods.getMethod();
                }
                else if (_methods.setMethod(pm.getPlugin("EssentialsEco"))) {
                    _plugin.method = _methods.getMethod();
                }
            }
    
     
  3. Offline

    Nijikokun

    I've tested it being last, it works because the plugin itself sends a plugin enable event AFTER yours is loaded. Thus causing the loop to happen. Make sure you are using 1.5

    Oh god, I looked at your coding... Don't do the same call OVER AND OVER, save it to a variable. that's seriously taxing on the databases and stuff.

    Here: https://gist.github.com/b3ec9be7651842e81353 (This should fix your issues) read up on how java works and how to reduce the amount of calls you make, a lot of your code isn't DRY
     
  4. Offline

    riuthamus

    This is amazing to see, saves countless hours for coders and is a great way for us to support all econ plugins. You sir deserve something...
     
  5. Offline

    narrowtux

    I think I will use it for my new plugin Showcase, thank you Nijikokun ;)
     
  6. Offline

    halvors

    @Nijikokun
    Thanks for the code, but i still get the error:
    Here is the code in SneakPlayerListener.java as before look at the rest on github: https://github.com/halvors/Sneak
    Code:
    package com.halvors.Sneak;
    
    import java.util.HashMap;
    
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.event.player.PlayerListener;
    
    import com.halvors.Sneak.util.WorldConfig;
    import com.nijikokun.register.payment.Method;
    import com.nijikokun.register.payment.Method.MethodAccount;
    
    public class SneakPlayerListener extends PlayerListener {
        private final Sneak plugin;
        private Method economy;
        private final HashMap<String, Long> delays = new HashMap<String, Long>();
    
        public SneakPlayerListener(final Sneak plugin) {
            this.plugin = plugin;
            this.economy = plugin.getMethod();
        }
    
        public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
            if (!event.isCancelled()) {
                Player player = event.getPlayer();
                Entity entity = event.getRightClicked();
                World world = player.getWorld();
                WorldConfig worldConfig = plugin.getConfigManager().getWorldConfig(world);
    
                if (entity instanceof Player) {
                    Player target = (Player)entity;
    
                    if (player.isSneaking() && target != null) {
                        if (Sneak.hasPermissions(player, "Sneak.use")) {      
                            String targetName = target.getName();
                            String playerName = player.getName();
                            
                            if ((economy.hasAccount(targetName)) && (economy.hasAccount(playerName))) {
                                MethodAccount targetAccount = economy.getAccount(targetName);
                                MethodAccount playerAccount = economy.getAccount(playerName);
                                
                                if ((targetAccount == null) || (playerAccount == null)) {
                                    return;
                                }
                                
                                int delay = 10 * 1000;
    
                                if (delays.containsKey(playerName)) {
                                    if ((System.currentTimeMillis() - delays.get(playerName)) < delay) {
                                        player.sendMessage(ChatColor.RED + "You can't sneak " + targetName + " so often.");
    
                                        return;
                                    }
                                }
    
                                double amount = targetAccount.balance() / 100 * 10.0;
                                String format = economy.format(amount);
    
                                if (targetAccount.hasEnough(amount)) {
                                    targetAccount.subtract(amount);
                                    playerAccount.add(amount);
    
                                    player.sendMessage(ChatColor.GREEN + "You sneaked " + targetName + " and got " + format + ".");
                                    target.sendMessage(ChatColor.RED + "You where sneaked by " + playerName + " and lost " + format + ".");
    
                                    delays.put(player.getName(), System.currentTimeMillis());
                                } else {
                                    player.sendMessage(ChatColor.RED + targetName + " have no money");
                                }
                            } else {
                                player.sendMessage(ChatColor.RED + "You or " + targetName + "don't have an account.");
                            }
                        }
                    }
                }
            }
        }
    }
    
    
     
  7. Offline

    Nijikokun

    Don't post the entire file, just the line. Also, that line points to this:
    if ((targetAccount == null) || (playerAccount == null)) {

    Try UNWRAPPING that:
    if(targetAccount == null || playerAccount == null) return false;

    You don't need opening / closing brackets.
     
  8. Offline

    halvors

  9. Offline

    Nijikokun

    I tested your plugin and I found out why.

    You try and grab Method before it's actually set. You call this:
    private final SneakPlayerListener playerListener = new SneakPlayerListener(this);
    before Method is set.

    What you should do in SneakPlayerListener is this:

    Code:
    public class SneakPlayerListener extends PlayerListener {
        private final Sneak plugin;
        private final HashMap<String, Long> delays = new HashMap<String, Long>();
        private Method economy;
        private ConfigManager configManager;
    
        public SneakPlayerListener(final Sneak plugin) {
            this.plugin = plugin;
            this.configManager = plugin.getConfigManager();
        }
    
        @Override
        public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
            this.economy = plugin.getMethod();
    or just stop using this.economy and just use plugin.getMethod().hasAccount() :p Eitherway, grab the method inside onPlayerInteractEntity instead of in the constructor
     
  10. Offline

    halvors

    Nijikokun, thanks :)
     
  11. Offline

    darknesschaos

    Sorry if I am blind to it but, using this, is there an easy way to get the currency name?

    Edit: also it seems I'm having trouble including this file in eclipse, how would I do it?

    Code:
    C:\Users\Andrew\Desktop\Bukkit>java -jar craftbukkit.jar
    [Lnet.minecraft.server.Statistic;@632d3205
    146 recipes
    [Lnet.minecraft.server.Statistic;@632d3205
    16 achievements
    03:06:19 [INFO] Starting minecraft server version Beta 1.5_02
    03:06:19 [INFO] Loading properties
    03:06:19 [INFO] Starting Minecraft server on *:25565
    03:06:19 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-729-
    g5ee3f0f-b766jnks (MC: 1.5_02)
    03:06:19 [INFO] Preparing level "world"
    03:06:19 [INFO] Preparing start region
    03:06:20 [INFO] Preparing spawn area: 89%
    03:06:20 [SEVERE] Could not load 'plugins\SignTrader.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:164)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:191)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:115)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:100)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:218)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:205)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:260)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    Caused by: java.lang.NoClassDefFoundError: com/nijikokun/register/payment/Method
    s
            at com.polycrypt.bukkit.tools.darknesschaos.EconServerListener.<init>(Ec
    onServerListener.java:20)
            at com.polycrypt.bukkit.plugin.darknesschaos.SignTrader.SignTrader.<init
    >(SignTrader.java:41)
            ... 13 more
    Caused by: java.lang.ClassNotFoundException: com.nijikokun.register.payment.Meth
    ods
            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)
            ... 15 more
    03:06:20 [INFO] [iConomy] Logging is currently disabled.
    03:06:20 [INFO] [iConomy] v5.01 (Eruanna) loaded.
    03:06:20 [INFO] [iConomy] Developed by: [Nijikokun]
    03:06:20 [INFO] Done (0.165s)! For help, type "help" or "?"
     
  12. Offline

    narrowtux

    The Method class has a method String format(double price) you type the price in there, and it will format it appropriate to the servers configuration.
     
  13. Offline

    darknesschaos

    ok, thanks. now what about my other problem?
     
  14. Offline

    _knot_

    Thank you for doing this. Just curious why this isn't on the OP of the iConomy thread or your signature. I feel that this is extremely helpful and needs more exposure!
     
  15. Offline

    fullwall

    @Nijikokun - having an issue with essentials eco being detected and used over iConomy.
     
  16. Offline

    Codisimus

    I don't know why but some users of my plugins have both iConomy and BOSEconomy installed. and want to use a specific one with my plugin. I allow them to set in the config what they want to use and then load the appropriate plugin. Does this load the first plugin it finds? or can I call a method to load a certain econ system.

    Thanks for doing this, I tried to connect with essentials many times but it was very annoying.
     
  17. Offline

    Nijikokun

    Loads the first it finds.

    They haven't added the part I need to the API to fix that, but as far as I know, they use Register in-essentials to utilize iConomy, so it should all go to iConomy either way.
     
  18. Offline

    Codisimus

    any chance a feature will be added to choose the econ system?
     
  19. Offline

    Nijikokun

    maybe if i get time
     
  20. Offline

    Codisimus

    ok, I'll keep an eye out for it. Do you happen to know the order that it would find these? like if there is iConomy and BOSEconomy will it always load iConomy? or can it be different everytime.
     
  21. Offline

    Ryannober

    So this plugin lets you use either or for lets say EssentialsEco and IConomy 5.0.1? Lets say i want to use a [buy] sign, will this plugin let either EsssentialsEco or IConomy work the sign? correct me if I'm wrong
     
  22. Offline

    arpey

    I think this plugin simply provides an interface for other plugin writers to use the aforementioned economy plugins.

    That is, you need a plugin that supports a [buy] sign. If the [buy] sign plugin supports Register, my understanding is that that plugin now supports any of the economy systems supported by Register. In a sense, Register sits in between a plugin—that could itself provide support for a [buy] sign—and an economy system (EssentialsEco, iConomy, etc).
     
  23. Offline

    Ryannober

    So basically, If my essentialsEco is not letting Iconomy's money buy the [buy] signs, this should fix that? lol
     
  24. Offline

    ChrizC

    hasBankAccount("Main", "ChrizC") returns false, when getBankAccount("Main", "ChrizC").balance() returns the balance of the bank account?
    Wut?

    Chris
     
  25. Offline

    Nijikokun

  26. Offline

    Moe041991

    sorry for me being a total newby. But iam not sure what this plugin excactly does (prolly of lacking english).

    can someone explain it to me in one or 2 sentences?
     
  27. Offline

    Zacky1

    Does this work with iConomy ??
     
  28. Offline

    aPunch

    This is not a plugin for users to download. It is a library for plugin developers to use to make our plugins compatible with ALL economy plugins (iConony, BOSEconomy, EssentialsEco). So yes, @Zacky1 , Register works with iConomy if a plugin supports it.
     
  29. Offline

    Nijikokun

    Released 1.8 (Yesterday)

    Allows for preference choosing:
    PHP:
            this.Methods = new Methods("Essentials"); // Prefers Essentials over any other economy plugins
    It still allows you to use new Methods(); but if you want a preference, initialize like above.

    Also, a note: Initialize Methods in onEnable and reference your plugin via this through the listener. If you don't know what I mean... Learn java.

    Notifying: @aPunch @fullwall @Acrobot @cereal @essentialsteam @halvors @fregaPT @Reil @MiHo @furekusu
     
  30. Offline

    Codisimus

    YES! Thank you, this was the only thing preventing me from using this. keep up the great work!

    EDIT: Proly a dumb question, but I don't see a save method. Do I assume that this automatically saves for all transactions in all plugins?
     
Thread Status:
Not open for further replies.

Share This Page