Solved Plugin crashes when I try to catch a UserDoesNotExistException

Discussion in 'Plugin Development' started by superrajiv, Sep 28, 2012.

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

    superrajiv

    Hi all,

    I'm trying to hook into the economy of Essentials, but each time I try to get the current ballance, I need to handle a UserDoesNotExistException, but when I do that my plugin crashes. Here is my code, it's not PHP but Java, ofcourse.
    I absolutely don't want to use Vault or anything else that requires an admin to install something else to make my plugin work.

    PHP:
    package nl.rajivmanichand.minebank;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
     
    import com.earth2me.essentials.Essentials;
    import com.earth2me.essentials.api.UserDoesNotExistException;
     
    public class 
    MineBank extends JavaPlugin{
     
        private 
    Logger log;
        private 
    Server server;
        private 
    Essentials ess null;
     
        @
    Override
        
    public void onEnable(){
         
            
    server getServer();
            
    log server.getLogger();
            
    log.info("MineBank started");
            
    PluginManager m getServer().getPluginManager();
            if(
    m.getPlugin("Essentials") == null){
                
    log.warning("MineBank didn't find Essentials");
                
    m.disablePlugin(this);
            }
            else{
                
    log.info("MineBank successfully connected to Essentials");
            }
        }
     
        @
    Override
        
    public void onDisable() {
            
    getLogger().info("MineBank stopped");
        }
     
        public 
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {
            if(
    cmd.getName().equalsIgnoreCase("basic")){
                if (!(
    sender instanceof Player)) {
                    
    sender.sendMessage("This command can only be run by a player.");
                    
    log.info("");
                } else {
                    
    Player player = (Playersender;
                }
                return 
    true;
            }
            return 
    false;
        }
     
        public 
    double getBalance(String playerName) {
            
    double balance;
     
            try {
                
    balance com.earth2me.essentials.api.Economy.getMoney(playerName);
            } catch (
    UserDoesNotExistException e) {
                
    balance 999;
            }
            return 
    balance;
        }
     
    }
    And here's my server log

    Code:
    2012-09-29 08:42:23 [INFO] Starting minecraft server version 1.3.2
    2012-09-29 08:42:23 [INFO] Loading properties
    2012-09-29 08:42:23 [INFO] Default game type: SURVIVAL
    2012-09-29 08:42:23 [INFO] Generating keypair
    2012-09-29 08:42:23 [INFO] Starting Minecraft server on *:25566
    2012-09-29 08:42:23 [WARNING] **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
    2012-09-29 08:42:23 [WARNING] The server will make no attempt to authenticate usernames. Beware.
    2012-09-29 08:42:23 [WARNING] While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.
    2012-09-29 08:42:23 [WARNING] To change this, set "online-mode" to "true" in the server.properties file.
    2012-09-29 08:42:23 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.2-R1.0-b2377jnks (MC: 1.3.2) (Implementing API version 1.3.2-R1.0)
    [B]2012-09-29 08:42:24 [SEVERE] Could not load 'plugins/MineBank.jar' in folder 'plugins'[/B]
    [B]org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/earth2me/essentials/api/UserDoesNotExistException[/B]
    [B]    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:154)[/B]
    [B]    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)[/B]
    [B]    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)[/B]
    [B]    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:223)[/B]
    [B]    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:199)[/B]
    [B]    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)[/B]
    [B]    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)[/B]
    [B]    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)[/B]
    [B]    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)[/B]
    [B]    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)[/B]
    [B]Caused by: java.lang.NoClassDefFoundError: com/earth2me/essentials/api/UserDoesNotExistException[/B]
    [B]    at java.lang.Class.forName0(Native Method)[/B]
    [B]    at java.lang.Class.forName(Class.java:247)[/B]
    [B]    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:143)[/B]
    [B]    ... 9 more[/B]
    [B]Caused by: java.lang.ClassNotFoundException: com.earth2me.essentials.api.UserDoesNotExistException[/B]
    [B]    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)[/B]
    [B]    at java.security.AccessController.doPrivileged(Native Method)[/B]
    [B]    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)[/B]
    [B]    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:44)[/B]
    [B]    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)[/B]
    [B]    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)[/B]
    [B]    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[/B]
    [B]    ... 12 more[/B]
    2012-09-29 08:42:24 [INFO] [Essentials] Loading Essentials v2.9.3
    2012-09-29 08:42:24 [INFO] Preparing level "world"
    2012-09-29 08:42:24 [INFO] Preparing start region for level 0 (Seed: -2747346370045058354)
    2012-09-29 08:42:24 [INFO] Preparing start region for level 1 (Seed: -2747346370045058354)
    2012-09-29 08:42:25 [INFO] Preparing start region for level 2 (Seed: -2747346370045058354)
    2012-09-29 08:42:25 [INFO] Preparing spawn area: 28%
    2012-09-29 08:42:25 [INFO] [Essentials] Enabling Essentials v2.9.3
    2012-09-29 08:42:25 [INFO] Essentials: Using config based permissions. Enable superperms in config.
    2012-09-29 08:42:25 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2012-09-29 08:42:26 [INFO] Done (1,836s)! For help, type "help" or "?"
     
  2. Offline

    brord

    Where exacly do you call getBalance?
     
  3. Offline

    Tirelessly

    I'm confused, you want them to be forced to use Essentials above all things but don't want them to install vault? That's pretty twisted.
     
  4. Offline

    8thDimension

    You marked your problem as solved but I'm sorry to say this but I think restricting your economy plugin only to Essentials is bad practice. Cutting out Vault because you don't want users to have to download another plugin is ridiculous considering how many major/commonly-used plugins already require Vault.

    Also, it cuts out those who use a different economy plugin from using your plugin
     
  5. Offline

    superrajiv

    Yeah, I figured that out too, I know use Vault.
     
  6. Offline

    Sleaker

    Let me know if you have trouble with it, or need help on the Vault forum/page.
     
Thread Status:
Not open for further replies.

Share This Page