Annoying Bug referencing to a external dependency?

Discussion in 'Plugin Development' started by kmccmk9, Feb 10, 2013.

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

    kmccmk9

    Hello, so I have this plugin and at one point it had worked with njiko permissions. However, I have since removed all of the code referring to njiko permission and the import for it. For some reason, when executing the command on any server, it throws an internal error. I check the error and it says I'm referencing njiko permissions somewhere. I seriously can't seem to spot the error in my code. If anyone is able to help I would really appreciate it.

    Code:
    package com.kmccmk9.ServerReloader;
     
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Logger;
     
    /**
    * ServerReloader for Bukkit
    *
    * @author kmccmk9
    */
     
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.kmccmk9.ServerReloader.ServerReloader;
     
    public class ServerReloader extends JavaPlugin {
        Server server;
        Logger log = Logger.getLogger("Minecraft");
        Boolean autoreload;
        Boolean displaytext;
        int autotime;
        int autotime2;
        int autotime3;
        int time_2;
        int time2_2;
        int time3_2;
        Player players[];
        ConsoleCommandSender autosender;
        static String mainDirectory = "plugins/ServerReloader"; //sets the main directory for easy reference
        static File settings = new File(mainDirectory + File.separator + "plugin.settings"); //the file separator is the / sign, this will create a new Zones.dat files in the mainDirectory variable listed above, if no Zones directory exists then it will automatically be made along with the file.
        static Properties settingsproperty = new Properties(); //creates a new properties file
        public void onDisable() {
            // TODO Auto-generated method stub
            log.info("ServerReloader has been disabled.");
        }
     
        public void onEnable() {
            // TODO Auto-generated method stub
            server = this.getServer();
            log.info("ServerReloader has been enabled.");
            //Setup Files
            new File(mainDirectory).mkdir(); //makes the Zones directory/folder in the plugins directory
            if(!settings.exists()){ //Checks to see if the zones file exists, defined above, if it doesn't exist then it will do the following. the ! turns the whole statement around, checking that the file doesn't exist instead of if it exists.
                try { //try catch clause explained below in tutorial
                    settings.createNewFile(); //creates the file zones.dat
                    FileOutputStream out = new FileOutputStream(settings); //creates a new output steam needed to write to the file
                    settingsproperty.put("autoreload", "false"); //put the property ZoneCount with a value of 0 into the properties file, this will show up as ZoneCount=0 in the properties file.
                    settingsproperty.put("time", "5");
                    settingsproperty.put("displaytext", "true");
                    settingsproperty.store(out, "Feel free to edit this config!"); //You need this line! It stores what you just put into the file and adds a comment.
                    out.flush();  //Explained below in tutorial
                    out.close(); //Closes the output stream as it is not needed anymore.
                } catch (IOException ex) {
                    ex.printStackTrace(); //explained below.
                }
     
            } else {
               
                messagesloadProcedure();
                AutoReloadProcedure();
     
            }
        }
     
        private void messagesloadProcedure() {
            try {
                FileInputStream in = new FileInputStream(settings);
                settingsproperty.load(in);
                autoreload = Boolean.valueOf(settingsproperty.getProperty("autoreload"));
                displaytext = Boolean.valueOf(settingsproperty.getProperty("displaytext"));
                autotime = Integer.parseInt(settingsproperty.getProperty("time"));
                in.close();
            } catch (IOException ex)
            {
                ex.printStackTrace();
            }
        }
       
        private void AutoReloadProcedure() {
            //AutoReload
            if (autoreload == true)
            {
                autotime = autotime * 60;
                autotime2 = autotime / 2;
                autotime3 = autotime - 15;
                if (displaytext == true)
                {
                server.broadcastMessage(ChatColor.GREEN + "Reload Complete");
                server.broadcastMessage(ChatColor.LIGHT_PURPLE + "[Server] The server will reload in " + autotime/60 + " minutes");
                }
                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        if (displaytext == true)
                        {
                        server.dispatchCommand(server.getConsoleSender(), "say Server Reloading in " + autotime2/60 + " minutes");
                        }
                    }
                }, autotime2 * 20L);
                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        if (displaytext == true)
                        {
                        server.dispatchCommand(server.getConsoleSender(), "say Server Reloading in" + " 10 seconds");
                        }
                    }
                }, autotime3 * 20L);
                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        if (displaytext == true)
                        {
                        server.dispatchCommand(server.getConsoleSender(), "say Server Reloading");
                        }
                        server.dispatchCommand(server.getConsoleSender(), "reload");
                    }
                }, autotime * 20L);
            }
        }
     
        public boolean onCommand(final CommandSender sender, Command command, String commandLabel, String[] args)
        {
            String enteredtime;
            Boolean TrueFalse = null;
            int time;
            final int time2;
            final int time3;
            if (sender instanceof Player) {
                final Player player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("serverreload")) {
                    if (args.length > 0)
                    {
                        enteredtime = args[0];
                        if (enteredtime.equalsIgnoreCase("help"))
                        {
                            player.sendMessage("The correct format is \"/serverreload <time in minutes>\"");
                            player.sendMessage("Typing \"/serverreload autoreload <true/false>\" will turn AutoReload on or off");
                            player.sendMessage("Using /serverreload help - Will list the help file");
                            player.sendMessage("Using /serverstop <time in minutes> will stop the server in that ammount of time");
                        }
                        if (enteredtime.equalsIgnoreCase("autoreload"))
                        {
                            if (args.length > 1)
                            {
                                TrueFalse = Boolean.parseBoolean(args[1]);
                            }
                            player.sendMessage("AutoReload changed to " + ChatColor.DARK_RED + TrueFalse.toString());
                            if (TrueFalse.toString().equalsIgnoreCase("true"))
                            {
                                autoreload = true;
                                settingsproperty.setProperty("autoreload", "true");
                                AutoReloadProcedure();
                            }
                            if (TrueFalse.toString().equalsIgnoreCase("false"))
                            {
                                autoreload = false;
                                settingsproperty.setProperty("autoreload", "false");
                            }
                        }
                        else if (!enteredtime.equalsIgnoreCase("help") && !enteredtime.equalsIgnoreCase("autoreload"))
                        {
                            if (autoreload == false)
                            {
                                time = Integer.parseInt(enteredtime);
                                time = time * 60;
                                time2 = time / 2;
                                time3 = time - 15;
                                if (player.isOp() /*|| player.hasPermission("serverreloader.admin")*/)
                                {
                                    if (displaytext == true)
                                    {
                                    server.dispatchCommand(sender, "say The server will reload in " + time/60 + " minutes");
                                    }
                                    server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                        public void run() {
                                            if (displaytext == true)
                                            {
                                            server.dispatchCommand(sender, "say Server Reloading in " + time2/60 + " minutes");
                                            }
                                        }
                                    }, time2 * 20L);
                                    server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                        public void run() {
                                            if (displaytext == true)
                                            {
                                            server.dispatchCommand(sender, "say Server Reloading in" + " 10 seconds");
                                            }
                                        }
                                    }, time3 * 20L);
                                    server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                        public void run() {
                                            if (displaytext == true)
                                            {
                                            server.dispatchCommand(sender, "say Server Reloading");
                                            }
                                            player.performCommand("reload");
                                        }
                                    }, time * 20L);
                                }
                            }
                            if (autoreload == true)
                            {
                                player.sendMessage(ChatColor.DARK_RED + "This is not allowed when auto reload in activated. Contact an admin for more information");
                            }
                        }
                    }
                }
                if (commandLabel.equalsIgnoreCase("serverstop"))
                {
                    if (args.length > 0)
                    {
                        enteredtime = args[0];
                        if (enteredtime.equalsIgnoreCase("help"))
                        {
                            player.sendMessage("The correct format is \"/serverreload <time in minutes>\"");
                            player.sendMessage("Typing \"/serverreload autoreload <true/false>\" will turn AutoReload on or off");
                            player.sendMessage("Using /serverreload help - Will list the help file");
                            player.sendMessage("Using /serverstop <time in minutes> will stop the server in that ammount of time");
                        }
                        else if (!enteredtime.equalsIgnoreCase("help"))
                        {
                        time_2 = Integer.parseInt(enteredtime);
                        time_2 = time_2 * 60;
                        time2_2 = time_2 / 2;
                        time3_2 = time_2 - 15;
                        if (player.isOp() /*|| player.hasPermission("serverreloader.admin")*/)
                        {
                            if (displaytext == true)
                            {
                            server.dispatchCommand(sender, "say The server will stop in " + time_2/60 + " minutes");
                            }
                            server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                public void run() {
                                    if (displaytext == true)
                                    {
                                    server.dispatchCommand(sender, "say Server Stopping in " + time2_2/60 + " minutes");
                                    }
                                }
                            }, time2_2 * 20L);
                            server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                public void run() {
                                    if (displaytext == true)
                                    {
                                    server.dispatchCommand(sender, "say Server Stopping in" + " 10 seconds");
                                    }
                                }
                            }, time3_2 * 20L);
                            server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                public void run() {
                                    if (displaytext == true)
                                    {
                                    server.dispatchCommand(sender, "say Server Stopping");
                                    }
                                    player.performCommand("stop");
                                }
                            }, time_2 * 20L);
                            }
                        }
                    }
                }
            }
            return true;
        }
    }
    
     
  2. Did you test it on your own server to be sure that you're checking the code of the same version you tested ?

    You should also post the stack trace and point to the exact line where it triggers.

    Also, I searched that code for "perm" and I could only find 2 codes that were even commented out... I'm not sure that's even the code that has the problem... unless the error means something totally diferent, post it :p
     
  3. Offline

    kmccmk9

    Sure thing. The error reads,

    Code:
    Unhandled exception executing command 'serverreload' in plugin ServerReloader v1.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
        at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchCommand(CraftServer.java:514)
        at net.minecraft.server.v1_4_R1.PlayerConnection.handleCommand(PlayerConnection.java:980)
        at net.minecraft.server.v1_4_R1.PlayerConnection.chat(PlayerConnection.java:898)
        at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:853)
        at org.getspout.spout.SpoutPlayerConnection.a(SpoutPlayerConnection.java:121)
        at net.minecraft.server.v1_4_R1.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_4_R1.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.v1_4_R1.PlayerConnection.d(PlayerConnection.java:113)
        at org.getspout.spout.SpoutPlayerConnection.d(SpoutPlayerConnection.java:196)
        at net.minecraft.server.v1_4_R1.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    
    Code:
    Caused by: java.lang.NoClassDefFoundError: com/nijiko/permissions/PermissionHandler
        at com.kmccmk9.ServerReloader.ServerReloader.onCommand(ServerReloader.java:193)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 17 more
    Caused by: java.lang.ClassNotFoundException: com.nijiko.permissions.PermissionHandler
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 19 more
    2013-02-10 02:31:48
    So I really don't know where I'm referencing the njiko permissions...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Well something is out of date, either the plugin that triggered the stacktrace or the code because the line numbers don't match to anything relevant, it says 193 and in your code line 193 is "if (displaytext == true)" which can't possibly trigger that stacktrace.

    Recompile your plugin and re-test it, also if there are other plugins that your plugin doesn't depend on you should temporary remove them too.
     
  5. Offline

    kmccmk9

    I have recompiled, and retested. My plugin does not depend on anything else, still I get the same error.
     
  6. Well, if you want you can post the jar and I'll see if I can find the issue.
     
  7. Offline

    kmccmk9

    Ok thanks I'd appreciate that...link to a pastebin or the jar file itself?

    Link to JAR
     
  8. Well, there was no need to run it because that jar's code does does import nijiko's permissions.

    It has an extra setupPermissions() method:
    Code:
      private void setupPermissions() {
        Plugin permissionsPlugin = getServer().getPluginManager().getPlugin("Permissions");
    
        if (permissionHandler == null)
          if (permissionsPlugin != null)
            permissionHandler = ((Permissions)permissionsPlugin).getHandler();
          else
            System.out.println("Permission system not detected, defaulting to OP");
      }
    
    And line 193 does fit according to the stacktrace:
    Code:
    if ((permissionHandler.has(player, "serverreloader.admin")) || (player.isOp()) || (player.hasPermission("serverreloader.admin")))
    So obviously you've mixed up your jars :p
     
  9. Offline

    kmccmk9

    Wait I'm confused what did I do wrong? Also, I just tried a plugin called Poll, and it gave the same java error. So is it possible there is a plugin just messing with them or is there a line like you had pointed out?
     
  10. Offline

    Jeyge

    The jar you linked does not contain your new code and instead has the old code in it. Either you didn't correctly export your new changes to your jar or you linked an old version of it.
     
  11. Offline

    kmccmk9

    Ok well I just re-exported and reuploaded so the link should be to the correct one now??
     
  12. Offline

    Jeyge

    Still the same plugin which tries to access all of those things you don't want it to. You should check to make sure the location you are exporting to is the same location you are uploading from and/or make sure you are actually exporting from the right project.
     
  13. Offline

    kmccmk9

    Ok I checked the path. Deleted what was there and it should now be working?
     
  14. Offline

    Jeyge

    If you have your new source in your project and you export/compile it to the right place, then you should be set. No one can actually see what you are doing so we can't actually say if you are doing that part of it right or not. Just check for errors when you do and as long as when you run it on your server it no longer throws the same error, you are good to go.
     
    kmccmk9 likes this.
Thread Status:
Not open for further replies.

Share This Page