Plugin not loading?

Discussion in 'Plugin Development' started by ledship, Jan 3, 2014.

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

    ledship

    Hi, I made a plugin for my network and I tried to put it on a server but when I reload the server I get this error here

    This is the code
    Code:java
    1. package com.ledscraft.ledscraft;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin{
    14. public static Main plugin;
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. int counter = 0;
    17.  
    18. @Override
    19. public void onDisable() {
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    22. }
    23.  
    24. @Override
    25. public void onEnable() {
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + "Version " + pdfFile.getVersion() + " Has Been Enabled!");
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    31. Player player = (Player) sender;
    32. if(commandLabel.equalsIgnoreCase("time")){
    33. if(player.isOp()){
    34. player.sendMessage(ChatColor.RED + "Usage: /time day");
    35. }else{
    36. player.sendMessage(ChatColor.RED + "You do not have permission to do this!");
    37. }if(player.isOp()){
    38. if(args[0].equalsIgnoreCase("day")){
    39. player.sendMessage(ChatColor.GREEN + "Time set to day");
    40. Bukkit.dispatchCommand(sender, "time set day");
    41. }
    42.  
    43. }if(player.isOp()){
    44. if(args[0].equalsIgnoreCase("night")){
    45. player.sendMessage(ChatColor.GREEN + "Time set to night.");
    46. Bukkit.dispatchCommand(sender, "time set night");
    47. }
    48. }
    49. }
    50. return false;
    51. }
    52. }



    Help me please.
     
  2. Offline

    Blingdaddy1

    Any stacktraces in console? Can you also post your plugin.yml
     
  3. Offline

    ledship


    I dont know what a stacktrace is or how to tell if there are any in the console, But heres my plugin.yml http://pastebin.com/91iSpv6f
     
  4. Offline

    lordbobby104

    ledship seems to be a problem with your plugin.yml try running it on a local server so you can get the whole error message
     
  5. Offline

    Blingdaddy1

    a stack trace is an error in console. Here's an example: [​IMG]

    If there's a stacktrace error, it really helps with finding an error
     
  6. Offline

    ledship


    I posted a link to the error in the console -_-
     
  7. Offline

    Blingdaddy1

    Oh I didnt see it xD
     
  8. Offline

    Drkmaster83

    I would say make the pdffile private and put it before everything as a class declaration. Then, when the plugin is disabling, grab that variable and use it for its information.
     
  9. Offline

    ledship


    Heres the log: http://pastebin.com/P2Zh8FFn


    I dont understand, Sorry Im a noob at this.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  10. Offline

    lordbobby104

    ledship the issue is that you have an invalid plugin description file try redoing it or exporting your jar again
     
  11. Offline

    Drkmaster83

    On second thought, maybe try removing the ">" from your description. I know that this shouldn't be the main issue, but there may be an issue with its YAML condition.

    Edit: ledship What I mean by make it a class-declared variable is this:
    Code:
    public class Main extends JavaPlugin{
      private PluginDescriptionFile pdfFile;
      public static Main plugin;
      public final Logger logger = Logger.getLogger("Minecraft");  
     
      @Override
      public void onEnable(){
        pdfFile = this.getDescription(); //Initializing the variable upon startup, can now be used throughout the whole class
        logger.info("Main v" + pdfFile.getVersion() + " has been enabled!");
      }
    }
    
     
  12. Offline

    ledship


    Removed it, And I found out what the error was :D I didnt put the right thing in my plugin.yml for where the main class is, But when I do /time it says what I want it to say but it always says An internal error occurred while attempting to perform this command
    And also, When I do /time day it says Usage: /time day (Next line) Time set to day even when it isnt and then Usage: /time day again on the next line?
     
  13. Offline

    Techy4198

    ledship looking at the structure of your if statements, I think you probably have not very much basic knowledge of java.
     
  14. Offline

    Drkmaster83

    When the internal error occurs, post the error that's in the console as well as your plugin.yml and onCommand() method.

    Edit:
    Techy4198... Ahem...
     
  15. Offline

    Techy4198

    Drkmaster83 I assumed he meant a noob at bukkit, not a noob at java, sorry
     
  16. Offline

    ledship


    I only have what a tutorial told me, But Its been enough to make 5 plugins which actually work and have permissions and that


    Console error: http://pastebin.com/mz1RiUsv Plugin.yml: http://pastebin.com/sPXYE7Ex and I didnt use any onCommand() method, I did
    Code:java
    1. Bukkit.dispatchCommand(sender, "time set night");
    because I wanted it to run the normal minecraft time set command, if thats what your talking about because I dont know really lol.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  17. Offline

    Drkmaster83

    Knowing how to make a plugin is easy. Knowing how to make a plugin work and understand why it works is the hard part. I'd recommend looking up some more advanced concepts alongside your Bukkit coding and thinking about how you can use those in plugins. But knowing how to debug stack traces and solve problems is an absolute must, so I'd recommend looking at this thread.

    A few pre-requisites for coding plugins is basic knowledge of YAML, obviously moderate Java knowledge, and a touch of work-ethic for the debugging portion of things.
     
  18. Offline

    ledship


    I understand why the plugins I've already made work(Apart from this one)
     
  19. Offline

    Drkmaster83

    Sorry about the post above, the Bukkit infrastructure is periodically going down for me, so my responses are delayed. Anyways, the structure of your onCommand(), as expected with a new Java programmer, is structured inefficiently and confusingly. You use the "else" statement at the end of "if" or "else-if" statements, never in the middle of them.

    Secondly, you're checking multiple times if the sender is an OP on separate occasions instead of putting everything in one area. I'll organize this, and show it to you in a before and after fashion. Afterwards, I will link you to a thread in which I helped someone with the onCommand() method.

    Before:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
      Player player = (Player) sender;
      if(commandLabel.equalsIgnoreCase("time")){
        if(player.isOp()){
          player.sendMessage(ChatColor.RED + "Usage: /time day");
        }else{
          player.sendMessage(ChatColor.RED + "You do not have permission to do this!");
        }if(player.isOp()){
          if(args[0].equalsIgnoreCase("day")){
            player.sendMessage(ChatColor.GREEN + "Time set to day");
          Bukkit.dispatchCommand(sender, "time set day");
          }
        }if(player.isOp()){
          if(args[0].equalsIgnoreCase("night")){
            player.sendMessage(ChatColor.GREEN + "Time set to night.");
            Bukkit.dispatchCommand(sender, "time set night");
          }
        }
      }
    return false;
    }
    
    After:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
      if(!(sender instanceof Player)) return false; //Checking if the sender is a player, not a console.
      Player player = (Player) sender; //This line, without the above if-statement, would throw an error if you typed "time" as console.
    if(commandLabel.equalsIgnoreCase("time"))
    {
      if(args.length == 0) //If there's nothing after the word after the "/", so just "/time"
      {
        if(player.isOp())
        {
          player.sendMessage(ChatColor.RED + "Usage: /time day");
        }
        else
        {
          player.sendMessage(ChatColor.RED + "You do not have permission to do this!");
        }
      }
      else if(args.length == 1) //If there's one word after the word after the "/", so just "/time day" or "/time night"
      {
        if(player.isOp())
        {
          if(args[0].equalsIgnoreCase("day"))
          {
            player.sendMessage(ChatColor.GREEN + "Time set to day!");
            Bukkit.dispatchCommand(sender, "time set 1000");
          }
          else if(args[0].equalsIgnoreCase("night"))
          {
            player.sendMessage(ChatColor.GREEN + "Time set to night!");
            Bukkit.dispatchCommand(sender, "time set 18000");
          }
          else
          {
            player.sendMessage(ChatColor.RED + "Time not applicable!");
            return false;
          }
        }
        else
        {
          player.sendMessage(ChatColor.RED + "You do not have permission to do this!");
        }
      }
      else if(args.length > 1)
      {
        if(player.isOp()) player.sendMessage(ChatColor.RED + "Too many arguments!");
        else player.sendMessage(ChatColor.RED + "You do not have permission to do this!");
      }
    }
    return false;
    }
    
    Edited the first time to apply correct spacing in code areas.
    Edited the second time: Here's the thread explaining the onCommand() method.
     
  20. Offline

    ledship




    Ohhh Ok thank you so much!
     
Thread Status:
Not open for further replies.

Share This Page