Solved Plugin won't work

Discussion in 'Plugin Development' started by idontcare1025, Nov 9, 2013.

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

    idontcare1025

    This is my source code:

    Code:Java
    1.  
    2. package appPlus;
    3.  
    4. import java.io.BufferedWriter;
    5. import java.io.FileWriter;
    6. import java.io.IOException;
    7. import java.io.PrintWriter;
    8.  
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class ApplicationPlus extends JavaPlugin {
    15.  
    16. @Override
    17. public void onEnable() {
    18. getLogger().info("onEnable has been invoked!");
    19. }
    20.  
    21. @Override
    22. public void onDisable() {
    23. getLogger().info("onDisable has been invoked");
    24. }
    25.  
    26. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    27. if (cmd.getName().equalsIgnoreCase("ap")) {
    28. Player p = (Player) sender;
    29. StringBuilder sb = new StringBuilder(args[0]);
    30. for (int i = 1; i < args.length; i++) {
    31. sb.append(" ").append(args[I]);[/I]
    32. [I] }[/I]
    33. String endSuggest = sb.toString();
    34. try {
    35. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("applications.txt", true)));
    36. out.println(p.getDisplayName());
    37. out.println(endSuggest);
    38. out.close();
    39. return true;
    40. } catch (IOException e) {
    41. return true;
    42. }
    43. }
    44. return false;
    45. }
    46.  
    47. }


    and this is my plugin.yml:

    Code:text
    1.  
    2. name: Application+
    3. main: appPlus.ApplicationPlus
    4. author: idontcare1025
    5. version: 1.0
    6. commands:
    7. ap:
    8. description: This command stores a user's application for staff.
    9. usage: /<command> [application]
    10. permission: <plugin name>.send
    11. permission-message: You don't have <permission>
    12.  


    Folder System:

    Applications+>src>appPlus>ApplicationsPlus
    Applications+>src>resources>plugin.yml




    Can anyone tell me why the plugin won't work?
     
  2. Offline

    GusGold

    idontcare1025
    I don't know if bukkit messed your formatting up, but your plugin.yml is white-space sensitive. Make sure you have 2 spaces per indent like so:
    Code:text
    1. commands:
    2. ap:
    3. description: Blah
    4. usage: ....

    Type /plugin in game and see if it shows your plugin as green.
    Also, your StringBuilder sb = new StringBuilder(args[0]); will give you an NPE if there are no arguments supplied, so surround it in an if statement:
    Code:java
    1. if (args.length > 0){

    Other than that, is there a stack trace error?
     
  3. Offline

    NinjaWAffles

    Also, please use ["syntax=Java"]["/syntax"] (without quotes) whenever posting your code. It makes it a lot cleaner.
     
  4. Offline

    xTrollxDudex

  5. Offline

    xDevious

    main: appPlus.ApplicationPlus

    You need to provide the project name, the package name, and the class name, like this:

    "ExampleProject.examplepackage.ExampleClass"
     
  6. Offline

    idontcare1025

    When I run the commands it says "Unknown Command"
     
  7. Offline

    NinjaWAffles

    Have you registered the command in your plugin.yml? Check here.
     
  8. Offline

    idontcare1025

    It won't appear in /plugins eithier

    and i did

    Still doesn't work

    Bukkit just messed up my formatting and how do I check if there's a stack trace error, and if there is one, how do I fix it?

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

    GusGold

    idontcare1025
    You will see it as an error in your server's console. It will look something like:
    Stack Trace (open)
    Code:text
    1. 10:33:40 [SEVERE] null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'YourCommand' in plugin YourPlugin v0.1
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    5. at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:523)
    6. at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:959)
    7. at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:877)
    8. at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:834)
    9. at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    10. at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    11. at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    12. at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    13. at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    14. at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    15. at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    16. at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    17. at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    18. at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    19. Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    20. at com.gusgold.YourPlugin.Commands.onCommand(Commands.java:48)
    21. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    22. ... 15 more
    In this case, it is because I tried to access an index of an array that is not set. You can tell what caused it by line 19, and where it occurred on line 20.
     
  10. Offline

    PolarCraft

    First line 26, 27 'The type of the expression must be an array type but it resolved to StringBuilder'. And your "{,}" are off.
     
  11. Offline

    AoH_Ruthless

    idontcare1025
    Generally I have noticed that errors in the plugin.yml don't cause errors in the Stack Trace. I could be wrong, that's just what I have seen.

    Just repaste the code. It would be EXTREMELY helpful if we could see the exact spacing of your plugin.yml
     
  12. Offline

    idontcare1025

    Thanks I fixed it because of you! Unknown symbol in plugin name
     
  13. Offline

    GusGold

Thread Status:
Not open for further replies.

Share This Page