Solved org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type

Discussion in 'Plugin Development' started by johnny_boy, Dec 29, 2019.

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

    johnny_boy

    Stacktrace:
    Code:
    [13:25:17 ERROR]: Could not load 'plugins\LocalMessage-v1.0.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type
      at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:924) ~[server.jar:git-Bukkit-e60fc34]
      at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:228) ~[server.jar:git-Bukkit-e60fc34]
      at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:155) ~[server.jar:git-Bukkit-e60fc34]
      at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:303) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.reload(CraftServer.java:727) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.Bukkit.reload(Bukkit.java:534) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:628) [server.jar:git-Bukkit-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:614) [server.jar:git-Bukkit-e60fc34]
      at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:408) [server.jar:git-Bukkit-e60fc34]
      at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:372) [server.jar:git-Bukkit-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:651) [server.jar:git-Bukkit-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:555) [server.jar:git-Bukkit-e60fc34]
      at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221]
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
      at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:906) ~[server.jar:git-Bukkit-e60fc34]
      ... 15 more
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map

    Think is has something to do with my plugin.yml but here are all my classes:

    plugin.yml
    Code:Java
    1.  
    2. main: me.johnny.localmessage.Main
    3. name: LocalMessage
    4. version: 1.0
    5. author: johnny boy#8125
    6. commands:
    7. lm:
    8. usage:"/lm <radius> <message>"
    9. rm:
    10. usage:"/rm <radius> <message>"
    11.  

    Main.java
    Code:Java
    1.  
    2. package me.johnny.localmessage;
    3. import java.io.File;
    4. import java.util.HashMap;
    5. import java.util.Map;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.configuration.file.YamlConfiguration;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import me.johnny.localmessage.commands.LocalMessageCommand;
    10. public class Main extends JavaPlugin {
    11.  
    12. private File configFile;
    13. private YamlConfiguration config;
    14. private HashMap<String, Object> defaults;
    15.  
    16. private void loadConfig() {
    17. configFile = new File(getDataFolder(), "config.yml");
    18.  
    19. if (!(configFile.exists())) {
    20. defaults = new HashMap<String, Object>();
    21.  
    22. getConfig().options().header("Use placeholder {maxradius} to replace it with the commands maximum range.");
    23. defaults.put("localmessage.command.usage", "&4Usage: /lm <radius> <message>");
    24. defaults.put("localmessage.command.maxradius_limit", "&4Error, you can't send a message more than {maxradius} blocks away");
    25. defaults.put("localmessage.command.maxradius_min", "&4Error, you can't send a message less than 0 blocks away");
    26. defaults.put("localmessage.command.maxradius", 20);
    27.  
    28. getConfig().getDefaults().addDefaults(defaults);
    29. getConfig().options().copyHeader(true);
    30. getConfig().options().copyDefaults(true);
    31.  
    32. saveConfig();
    33. }
    34. config = YamlConfiguration.loadConfiguration(configFile);
    35. }
    36.  
    37. @Override
    38. public void onEnable() {
    39. loadConfig();
    40.  
    41. getCommand("lm").setExecutor(new LocalMessageCommand(this));
    42. getCommand("rm").setExecutor(new LocalMessageCommand(this));
    43. }
    44.  
    45. @Override
    46. public void onDisable() {
    47. saveConfig();
    48. }
    49. }
    50.  

    LocalMessageCommand.java
    Code:Java
    1.  
    2. package me.johnny.localmessage.commands;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import me.johnny.localmessage.Main;
    10. public class LocalMessageCommand implements CommandExecutor {
    11.  
    12. private Main plugin;
    13. private int maxDistance;
    14. private Player pl;
    15.  
    16. public LocalMessageCommand(Main plugin) {
    17. this.plugin = plugin;
    18. }
    19.  
    20. private String cc(String str) {
    21. return ChatColor.translateAlternateColorCodes('&', str);
    22. }
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    25. if (!(sender instanceof Player)) {
    26. sender.sendMessage(ChatColor.DARK_RED + "You need to be ingame to use this command!");
    27. return false;
    28. }
    29.  
    30. if (args.length < 1 || args.length > 2) {
    31. String usage = plugin.getConfig().getString("localmessage.command.usage");
    32. pl.sendMessage(cc(usage));
    33. return false;
    34. }
    35.  
    36. try {
    37. if (Integer.getInteger(args[0]) > 20) {
    38. String error = plugin.getConfig().getString("localmessage.command.maxradius_limit");
    39. String finalError = error.replaceAll("{maxradius", String.valueOf(plugin.getConfig().getInt("localmessage.command.maxradius")));
    40. pl.sendMessage(cc(finalError));
    41. return false;
    42. } else if (Integer.getInteger(args[0]) < 1) {
    43. String error = plugin.getConfig().getString("localmessage.command.maxradius_min");
    44. pl.sendMessage(cc(error));
    45. return false;
    46. }
    47. } catch (Exception e) {
    48. String usage = plugin.getConfig().getString("localmessage.command.usage");
    49. pl.sendMessage(cc(usage));
    50. return false;
    51. }
    52. pl = (Player) sender;
    53. maxDistance = plugin.getConfig().getInt("localmessage.command.maxradius");
    54.  
    55. for (Player p : Bukkit.getOnlinePlayers()) {
    56.  
    57. if (p.getUniqueId() == pl.getUniqueId()) {
    58. continue;
    59. }
    60.  
    61. if (pl.getLocation().distance(p.getLocation()) <= (double) Integer.getInteger(args[0])) {
    62. if (pl.getLocation().distance(p.getLocation()) <= (double) maxDistance) {
    63.  
    64. StringBuilder b = new StringBuilder();
    65. for (int i = 1; args.length < i; i++) {
    66. b.append(args[i]);
    67. }
    68. p.sendMessage(cc(b.toString()));
    69. return false;
    70. }
    71. return false;
    72. }
    73. }
    74.  
    75. return false;
    76. }
    77. }
    78. [/i]

    Don't mind the messy code. I did try searching on google for a solid amount of time to no avail. I know it's a really simple fix I just don't know the issue. Thanks for reading.
     
  2. Online

    timtower Moderator Moderator

    @johnny_boy Code is not important for this issue.
    Your plugin.yml lacks some formatting,
    Usage needs two more spaces.
     
  3. Offline

    johnny_boy

    I did realise that and have fixed it. Thank you.
     
    timtower likes this.
Thread Status:
Not open for further replies.

Share This Page