[NEED HELP PLEASE READ!] Help with plugin/coding

Discussion in 'Plugin Development' started by Micro5, Apr 13, 2012.

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

    Micro5

    Hello everyone. Please help me. I did all of the coding and everything but a problem still consists.

    When I type the command in (/mod) then it still says unknown command.

    Here is the coding ( trademark on it so DONT STEAL):

    package me.LegendaryMacros.LegendaryMacros;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LegendaryMacros extends JavaPlugin {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("mod")){
    if (sender instanceof Player){
    Player[] onlinePlayers = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers ){
    player.sendMessage("Your message goes here!");
    }
    }
    }
    returnfalse;
    }

    Logger log;

    public void onEnable(){
    log = this.getLogger();
    log.info("Your message in console when enabling");
    }

    public void onDisable(){
    log = this.getLogger();
    log.info("Your message in console when disabling");
    }
    }
     
  2. Offline

    AmberK

    Code:
    log.info("Your message in console when enabling");
    log.info("Your message in console when enabling");
    player.sendMessage("Your message goes here!");
    package me.LegendaryMacros.LegendaryMacros;
    public class LegendaryMacros extends JavaPlugin {
    I get the strangest feeling this isn't your code, or trademarked. But for the sake of learning...

    You need to create a plugin.yml for your plugin, and include the vital information for it such as "author", "version", the startup, the commands you actually have... etc.
     
    CorrieKay likes this.
  3. Offline

    Micro5

    This is mine... I made it....

    I have a plugin.yml.

    My plugin works fine it's just when I type /mod it doesn't work and I don't get what to put.
     
  4. Offline

    CorrieKay

    well lets see your plugin.yml then :p

    also, we would need more than just "an error! help!"
     
  5. Offline

    Micro5

    name: LegendaryMacros
    main: me.LegendaryMacros.LegendaryMacros.LegendaryMacros
    description: This is a macro plugin.
    version: 0.1
     
  6. Offline

    CorrieKay

  7. Offline

    Micro5

    ? I am confused. Because it works for my other plugins but then again there isn't a command?

    ... :(
     
  8. Offline

    CorrieKay

    you have to register your commands in your plugin.yml.

    you said you tried to use /mod and it says unknown command? cuz you didnt register it in plugin.yml

    do this

    Code:
    commands:
      mod:
        description: "description here"
        permission: "permission here"
        usage: "syntax of how to use your command, such as /<command> <parameter1> <parameter2>"
    all of those child nodes (description, permission, and usage) are all optional. i think if you just wanted to register the command, you'd do
    Code:
    command:
      mod: {}
    though typically you should always include description and usage, for obvious reasons
     
  9. Offline

    Micro5

    So, I just add it in the plugin.yml?
     
  10. Offline

    Highace2

    Actually a part of the code is made by me. And I've given him permission to use it and trademark it. So don't complain.
     
    Micro5 likes this.
  11. Offline

    Orcem12

    @Micro5
    @Highace2
    @AmberK
    I hate to be that guy... But Mirco isn't nor doesn't need to trademark anything. For the code displayed is the most basic coding concept. Unless the coder steals declaration names from other plugins or EXACT copy of format you cannot trademark this. Simply because the same exact code can be found in 99% of plugins and on the Bukkit wiki under "General Plugin Example"

    And for the plugin.yml do this:
    Code:
    name: LegendaryMacros
    version: 1.0
    author: Micro5
    main: me.LegendaryMacros.LegendaryMacros.LegendaryMacros
    commands:
      mod:
        description: mod command
    Other values can be added to the command later.
     
  12. Offline

    Micro5


    Thanks for the help.

    I fixed it up but there is still a issue.
     
  13. Offline

    Orcem12

  14. Offline

    Micro5

    @Orcem12
    Everything is fine. I can now do /mod in game.

    The only problem is, I added /smod ( for another macro ) and then when I do it in the plugin.yml I put this.

    name: LegendaryMacros
    main: me.LegendaryMacros.LegendaryMacros.LegendaryMacros
    version: 0.1
    commands:
    mod:
    description: Plugin for macros.
    usage: /mod
    smod:
    description: Plugin for macros to make playing easier.
    usage: /smod

    it says that everything is ok but then when I put it in my plugins folder and reload the server it says it isn't in the plugins. It also says : well here you go :

    20:33:16 [INFO] [WorldEdit] Disabling WorldEdit v5.3
    20:33:16 [INFO] [MicroInventory] Disabling MicroInventory v0.1
    20:33:16 [INFO] [MicroInventory] Micro Inventory has been disabled!
    20:33:16 [INFO] 182 recipes
    20:33:16 [SEVERE] Could not load 'plugins/LegendaryMacros.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type
    at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:242)
    at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:42)
    at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:198)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:132)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
    at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:541)
    at org.bukkit.Bukkit.reload(Bukkit.java:182)
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:473)
    at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:469)
    at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:596)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:565)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
    at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:224)
    ... 14 more
    20:33:16 [INFO] [WorldEdit] Loading WorldEdit v5.3
    20:33:16 [INFO] [MicroInventory] Loading MicroInventory v0.1
    20:33:16 [INFO] [WorldEdit] Enabling WorldEdit v5.3
    20:33:16 [INFO] WEPIF: Using the Bukkit Permissions API.
    20:33:16 [INFO] [MicroInventory] Enabling MicroInventory v0.1
    20:33:16 [INFO] [MicroInventory] Micro Inventory has been enabled!
    20:33:16 [INFO] Server permissions file permissions.yml is empty, ignoring it
    20:33:16 [INFO] Reload complete.
    >pl
    20:33:17 [INFO] Plugins (2): WorldEdit, MicroInventory
    >hmm
    20:33:21 [INFO] Unknown command. Type "help" for help.
    >

    the code is now:

    package me.LegendaryMacros.LegendaryMacros;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LegendaryMacros extends JavaPlugin {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("mod")){
    if (sender instanceof Player){
    Player[] onlinePlayers = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers ){
    player.sendMessage("/g &6Need help? Message me. I can place &3Water, &4Lava, &cFire &6and set &3warps!");
    }
    }
    }
    if(cmd.getName().equalsIgnoreCase("smod")){
    if (sender instanceof Player){
    Player[] onlinePlayers1 = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers1 ){
    player.sendMessage("testetistestinets");
    }
    }
    }
    returnfalse;
    }


    Logger log;

    public void onEnable(){
    log = this.getLogger();
    log.info("Your message in console when enabling");
    }

    public void onDisable(){
    log = this.getLogger();
    log.info("Your message in console when disabling");
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  15. Offline

    AmberK

    I wasn't complaining. Merely commenting that he didn't make 100% of it. Also, it's not like I just was like "oh you didn't make this, screw off". I still tried to help :p

    Micro5 make sure you are spacing things out correctly. the plugin.yml uses a two-space hierarchy, so it needs to look like this:
    Code:
    commands:
      cmdname:
        description: derp
        usage: /cmdname
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  16. Offline

    Micro5

    But what is I have more than one command?
     
  17. Offline

    KILL3RTACO

    Then the format would then be as follows:
    Code:
    commands:
      cmd1:
        description:
        usage:
      cmd2:
        description:
        usage:
     
  18. Offline

    dillyg10

    Code:yaml
    1.  
    2. commands:
    3. mod:
    4. description: derp
    5. smod:
    6. description: derp
     
  19. Offline

    Micro5

    Is the coding for what I had ok ?

    package me.LegendaryMacros.LegendaryMacros;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LegendaryMacros extends JavaPlugin {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("mod")){
    if (sender instanceof Player){
    Player[] onlinePlayers = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers ){
    player.sendMessage("/g &6Need help? Message me. I can place &3Water, &4Lava, &cFire &6and set &3warps!");
    }
    }
    }
    if(cmd.getName().equalsIgnoreCase("smod")){
    if (sender instanceof Player){
    Player[] onlinePlayers1 = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers1 ){
    player.sendMessage("testetistestinets");
    }
    }
    }
    returnfalse;
    }


    Logger log;

    public void onEnable(){
    log = this.getLogger();
    log.info("Your message in console when enabling");
    }

    public void onDisable(){
    log = this.getLogger();
    log.info("Your message in console when disabling");
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  20. Offline

    dillyg10

    why is returnfalse; al one word? That needs to be return false, also put your onEnalbe, and onDisable methods at the top oh, and you need to add return true after you are done with mod and smod.
    sides that.. good :D.
     
  21. Offline

    KILL3RTACO

    Well except for this:
    Code:
    returnfalse;
    Then I think your fine.
    EDIT: d'oh seems dillyg10 beat me :p
     
  22. Offline

    Micro5

    let me try that . one second :)

    So the coding would now be this?

    package me.LegendaryMacros.LegendaryMacros;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LegendaryMacros extends JavaPlugin {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("mod")){
    if (sender instanceof Player){
    Player[] onlinePlayers = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers ){
    player.sendMessage("/g &6Need help? Message me. I can place &3Water, &4Lava, &cFire &6and set &3warps!");
    }
    return true;
    }
    }
    if(cmd.getName().equalsIgnoreCase("smod")){
    if (sender instanceof Player){
    Player[] onlinePlayers1 = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers1 ){
    player.sendMessage("testing");
    }
    return true;
    }
    }
    return false;
    }


    Logger log;

    public void onEnable(){
    log = this.getLogger();
    log.info("Your message in console when enabling");
    }

    public void onDisable(){
    log = this.getLogger();
    log.info("Your message in console when disabling");
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  23. Offline

    KILL3RTACO

    Yeah, it seems right, though it would be greatly appreciated if you would use the code tags in the future
     
  24. Offline

    Micro5

    When I put my plugin in, and it loads up it says this in console:

    Code:
    07:05:03 [SEVERE] Could not load 'plugins/LegendaryMacros.jar' in folder 'plugins'
    So here is everything that I used.

    Plugin.yml:

    name: LegendaryMacros
    main: me.LegendaryMacros.LegendaryMacros.LegendaryMacros
    version: 0.1
    commands:
    mod:
    description: Plugin for macros.
    usage: /mod
    smod:
    description: Plugin for macros to make playing easier.
    usage: /smod

    Coding:

    Code:
    package me.LegendaryMacros.LegendaryMacros;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class LegendaryMacros extends JavaPlugin {
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("mod")){
    if (sender instanceof Player){
    Player[] onlinePlayers = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers ){
    player.sendMessage("/g &6Need help? Message me. I can place &3Water, &4Lava, &cFire &6and set &3warps!");
    }
    return true;
    }
    }
    if(cmd.getName().equalsIgnoreCase("smod")){
    if (sender instanceof Player){
    Player[] onlinePlayers1 = getServer().getOnlinePlayers();
    for( Player player : onlinePlayers1 ){
    player.sendMessage("testing");
    }
    return true;
    }
    }
    return false;
    }
     
     
    Logger log;
     
    public void onEnable(){
    log = this.getLogger();
    log.info("Your message in console when enabling");
    }
     
    public void onDisable(){
    log = this.getLogger();
    log.info("Your message in console when disabling");
    }
    }
    
     
  25. Offline

    KILL3RTACO

    Can you post the rest of the error that was in the console?
     
  26. Offline

    Micro5

    Code:
    >reload
    07:21:57 [INFO] [WorldEdit] Disabling WorldEdit v5.3
    07:21:57 [INFO] [MicroInventory] Disabling MicroInventory v0.1
    07:21:57 [INFO] [MicroInventory] Micro Inventory has been disabled!
    07:21:57 [INFO] 182 recipes
    07:21:57 [SEVERE] Could not load 'plugins/LegendaryMacros.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type
        at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:242)
        at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:42)
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:198)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:132)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
        at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:541)
        at org.bukkit.Bukkit.reload(Bukkit.java:182)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:473)
        at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:469)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:596)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:565)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
        at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:224)
        ... 14 more
    07:21:57 [INFO] [WorldEdit] Loading WorldEdit v5.3
    07:21:57 [INFO] [MicroInventory] Loading MicroInventory v0.1
    07:21:57 [INFO] [WorldEdit] Enabling WorldEdit v5.3
    07:21:57 [INFO] WEPIF: Using the Bukkit Permissions API.
    07:21:57 [INFO] [MicroInventory] Enabling MicroInventory v0.1
    07:21:57 [INFO] [MicroInventory] Micro Inventory has been enabled!
    07:21:57 [INFO] Server permissions file permissions.yml is empty, ignoring it
    07:21:57 [INFO] Reload complete.
    >
    
     
  27. Offline

    KILL3RTACO

    Seems there is a problem in your plugin.yml... Can you post anything after (and including) the "command:" attribute?
     
Thread Status:
Not open for further replies.

Share This Page