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


    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.

    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.PluginManager;
    import com.earth2me.essentials.Essentials;
    import com.earth2me.essentials.api.UserDoesNotExistException;
    public class 
    MineBank extends JavaPlugin{
    Logger log;
    Server server;
    Essentials ess null;
    public void onEnable(){
    server getServer();
    log server.getLogger();
       "MineBank started");
    PluginManager m getServer().getPluginManager();
    m.getPlugin("Essentials") == null){
    log.warning("MineBank didn't find Essentials");
           "MineBank successfully connected to Essentials");
    public void onDisable() {
    getLogger().info("MineBank stopped");
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {
                if (!(
    sender instanceof Player)) {
    sender.sendMessage("This command can only be run by a player.");
                } else {
    Player player = (Playersender;
    double getBalance(String playerName) {
    double balance;
            try {
    balance com.earth2me.essentials.api.Economy.getMoney(playerName);
            } catch (
    UserDoesNotExistException e) {
    balance 999;
    And here's my server log

    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] 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 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[/B]
    [B]    at org.bukkit.plugin.SimplePluginManager.loadPlugin([/B]
    [B]    at org.bukkit.plugin.SimplePluginManager.loadPlugins([/B]
    [B]    at org.bukkit.craftbukkit.CraftServer.loadPlugins([/B]
    [B]    at org.bukkit.craftbukkit.CraftServer.<init>([/B]
    [B]    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>([/B]
    [B]    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)[/B]
    [B]    at net.minecraft.server.DedicatedServer.init([/B]
    [B]    at[/B]
    [B]    at[/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([/B]
    [B]    at[/B]
    [B]    ... 9 more[/B]
    [B]Caused by: java.lang.ClassNotFoundException: com.earth2me.essentials.api.UserDoesNotExistException[/B]
    [B]    at$[/B]
    [B]    at Method)[/B]
    [B]    at[/B]
    [B]    at[/B]
    [B]    at[/B]
    [B]    at java.lang.ClassLoader.loadClass([/B]
    [B]    at java.lang.ClassLoader.loadClass([/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


    Where exacly do you call getBalance?
  3. Offline


    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


    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


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


    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