What's Wrong With This Plugin?

Discussion in 'Plugin Development' started by SayHi2uTube, Oct 9, 2015.

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

    SayHi2uTube

    What's wrong with this? When I install the jar, it doesn't register as a plugin.

    Here'd my code:

    Code:
    package me.SayHi2uTube.Ram;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ram extends JavaPlugin
    {
      public void onDisable()
      {
        System.out.println("[Ram v1.0] Plugin Shut Down");
      }
    
      public void onEnable()
      {
        System.out.println("[Ram v1.0] Plugin Loaded");
        getCommand("ram").setExecutor(new CommandExecutor() {
          public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Ram.this.command_logic(sender);
            return true;
          }
        });
        getCommand("mem").setExecutor(new CommandExecutor() {
          public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Ram.this.command_logic(sender);
            return true;
          }
        });
        getCommand("memory").setExecutor(new CommandExecutor() {
            public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
              Ram.this.command_logic(sender);
              return true;
            }
          });
        getCommand("lag").setExecutor(new CommandExecutor() {
            public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
              Ram.this.command_logic(sender);
              return true;
            }
          });
      }
    
      public void command_logic(CommandSender sender) {
        Runtime runtime = Runtime.getRuntime();
        System.gc();
        if ((sender.isOp()) || (sender.hasPermission("ram.ram")))
          sender.sendMessage(ChatColor.GREEN + "[Used / Total / Free]  " + ChatColor.BLUE + (runtime.totalMemory() - runtime.freeMemory()) / 1048576L + " MB / " + runtime.totalMemory() / 1048576L + " MB / " + runtime.freeMemory() / 1048576L + " MB");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
        if ((sender.isOp()) || (sender.hasPermission("ram.version")))
          sender.sendMessage(ChatColor.AQUA + "[Ram v1.0]");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
      }
    }
    
    And Here's My plugin.yml
    Code:
    name: Ram
    main: me.SayHi2uTube.Ram.Ram
    version: 1.0
    description: >
                 Detects how much ram you have on your server.
    commands:
      ram:
        description: Tells you how much ram you have.
     
    Last edited: Oct 9, 2015
  2. Offline

    Scimiguy

    Can you please use the code tags to mark code? Easier to read

    Also, put @Override above your onEnable() and onDisable methods
     
  3. Offline

    RoboticPlayer

    Can you format your code? It's very difficult to read currently. Try using [ code=java ] // Your code [ /code ] brackets (without spaces). It may be that your plugin.yml is incorrectly configured, but I don't know since it's not formatted. Also, when you start the server, are there any stacktraces that show up in the server console?

    A) Java Naming Conventions: package names should be all lowercase
    B) onEnable() and onDisable() can be overridden
    C) Why are you creating classes within your main class for command executors? Instead, just do something like this
    Code:java
    1. package me.(yourname).(projectname)
    2.  
    3. public class Ram extends JavaPlugin {
    4. @Override
    5. public void onEnable() {
    6. // You don't actually need this unless you are dealing with more advanced code
    7. }
    8.  
    9. @Override
    10. public void onDisable() {
    11. // Also not needed
    12. }
    13.  
    14. @Override
    15. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    16. if (cmd.getName().equalsIgnoreCase("ram") {
    17. // Your checks and everything
    18. }
    19. }
    20. }

    D) You don't need to log when the plugin is enabled or disabled, Bukkit already does this
    E) Because of D, no need for onDisable in this case
    F) You can have your command_logic things inside of your command
    G) Unless this plugin is for private use, you might not want to allow a player to run a command because they are op. Just give op the default permission.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  4. Offline

    SayHi2uTube

    Changed spoiler to code.
     
    Last edited: Oct 9, 2015
  5. Offline

    Scimiguy

    Please edit the title of the thread and mark is as solved
     
  6. Offline

    SayHi2uTube

    So like:
    Code:
    package me.SayHi2uTube.Ram;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ram extends JavaPlugin
    {
      public void command_logic(CommandSender sender) {
        Runtime runtime = Runtime.getRuntime();
        System.gc();
        if (sender.hasPermission("ram.ram"))
          sender.sendMessage(ChatColor.GREEN + "[Used / Total / Free]  " + ChatColor.BLUE + (runtime.totalMemory() - runtime.freeMemory()) / 1048576L + " MB / " + runtime.totalMemory() / 1048576L + " MB / " + runtime.freeMemory() / 1048576L + " MB");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
        if (sender.hasPermission("ram.version"))
          sender.sendMessage(ChatColor.AQUA + "[Ram v1.0]");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
      } 
    }
    
     
  7. Offline

    RoboticPlayer

    @SayHi2uTube Did you just fix some issues or is your problem solved?

    Edit: (to the latest post) No, you still need your onCommand method, just no need to set an executor for it.
     
  8. Offline

    SayHi2uTube

    Fix the code tags

    So
    Code:
    package me.SayHi2uTube.Ram;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ram extends JavaPlugin
    {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        Runtime runtime = Runtime.getRuntime();
        System.gc();
        if (sender.hasPermission("ram.ram"))
          sender.sendMessage(ChatColor.GREEN + "[Used / Total / Free]  " + ChatColor.BLUE + (runtime.totalMemory() - runtime.freeMemory()) / 1048576L + " MB / " + runtime.totalMemory() / 1048576L + " MB / " + runtime.freeMemory() / 1048576L + " MB");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
        if (sender.hasPermission("ram.version"))
          sender.sendMessage(ChatColor.AQUA + "[Ram v1.0]");
        else
          sender.sendMessage(ChatColor.RED + "[Ram v1.0] You Do Not Have Permission to Execute This Command");
        return false;
      }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  9. Offline

    Scimiguy

    You can follow this tutorial for help on how to handle commands
     
  10. Offline

    RoboticPlayer

    @SayHi2uTube Sort of. I recommend that you check which command it is by doing
    Code:java
    1. if (cmd.getName().equalsIgnoreCase(String) {
    2. // Your code
    3. }

    Edit: Also, add an @Override right before your onCommand method:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    3. // Your code
    4. }
     
  11. Offline

    SayHi2uTube

    So this? I simplified it
    Code:
    package me.SayHi2uTube.Ram;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ram extends JavaPlugin
    {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        Runtime runtime = Runtime.getRuntime();
        System.gc();
        if (cmd.getName().equalsIgnoreCase("ram")) {
          sender.sendMessage(ChatColor.GREEN + "[Used / Total / Free]  " + ChatColor.BLUE + (runtime.totalMemory() - runtime.freeMemory()) / 1048576L + " MB / " + runtime.totalMemory() / 1048576L + " MB / " + runtime.freeMemory() / 1048576L + " MB");
          return false;
        }
        return false;
      }
    }
     
  12. Offline

    caderape

    @SayHi2uTube


    your description is weird.
    What is exactly your problem ?
     
    Last edited: Oct 9, 2015
  13. Offline

    SayHi2uTube

    The plugin doesn't register and therefore the plugin won't work.
     
  14. Offline

    mythbusterma

    @SayHi2uTube

    If it isn't showing up, it is one of two things. Either:

    1. There's a stack trace in your console
    2. You didn't actually put it on your server

    Which one is it?
     
    Zombie_Striker and boomboompower like this.
  15. Offline

    Scimiguy

    @mythbusterma Not True, it could be a plugin.yml issue, or maybe he's looking at it wrong

    Does your console say loading Plugin Ram on startup?
     
  16. Offline

    RoboticPlayer

    @Scimiguy If there is an issue with the plugin.yml, there will be a stacktrace.
     
  17. Offline

    mythbusterma

    @Scimiguy

    .....think before you type.
     
  18. Offline

    pablo67340

    I was just reading this thread for shits and gigs, i dont use this forum much because i use spigot... But why do i remember your name so well?
     
  19. Offline

    mythbusterma

    @pablo67340

    I'm not sure, I post here quite often, and have for quite a while, as you can see by my profile.

    I also do Trident.
     
  20. Offline

    Zombie_Striker

    @SayHi2uTube
    1. JavaNamingConventions: Packagenames should all be lowercase.
    2. If the command sent is the same as the command you're checking, return true.
    Does it show it gets enabled in the CMD? Does it show any errors? Do you happen to have any other plugins with the same package name or plugin name?
     
  21. Offline

    SayHi2uTube

    So
    Code:
    package me.SayHi2uTube.Ram;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ram extends JavaPlugin
    {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Runtime runtime = Runtime.getRuntime();
        System.gc();
        if (cmd.getName().equalsIgnoreCase("ram")) {
          sender.sendMessage(ChatColor.GREEN + "[Used / Total / Free]  " + ChatColor.BLUE + (runtime.totalMemory() - runtime.freeMemory()) / 1048576L + " MB / " + runtime.totalMemory() / 1048576L + " MB / " + runtime.freeMemory() / 1048576L + " MB");
          return true;
        }
        return false;
      }
    }
     
  22. Offline

    Zombie_Striker

    JavaNamingConventions: Packagenames should all be lowercase.
    This still needs to be fixed.

    Code:
    description: >
                 Detects how much ram you have on your server.
    This might also cause the problem. I don't thing the character \n (next line) is allowed for yml files.

    May we also see what the command prompt prints out when you start up your server?
     
  23. Offline

    SayHi2uTube

    It doesn't say anything. At least nothing that I can see.
     
  24. Offline

    Zombie_Striker

    @SayHi2uTube

    I think you mean the server command prompt said nothing, correct? If so, that means your server isn't even running. If your server is running and there is no text in the cmd prompt, then there is something buggy with your version of bukkit.
     
  25. Offline

    SayHi2uTube

  26. Offline

    Zombie_Striker

    @SayHi2uTube
    I'm not asking for your JAR, I'm asking for your what your server prompt prints out when you run your server.

    Seeing your jar is pointless unless I know what your server is doing with it.
     
  27. Offline

    SayHi2uTube

  28. Offline

    Zombie_Striker

    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml

    Are you sure you are putting your plugin.yml in the correct spot? It should not be in any packaging.
     
  29. Offline

    SayHi2uTube

    Turns out that was the problem. Thanks!
     
  30. Offline

    Scimiguy

    Both of you think before you type next time.
     
    Zombie_Striker likes this.
  31. Offline

    RoboticPlayer

    @Scimiguy What do you mean by that? I did think.
    There was an issue with the plugin.yml, and there was a stacktrace.
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page