Help w/ my plugin!

Discussion in 'Plugin Development' started by tooncool64, May 6, 2014.

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

    tooncool64

    My plugin loads fine on my server., But when i do my command /hello, it doesnt do anything,
    Also this: (My plugin is called test plugin)
    Code:
    [TestPlugin] Enabling TestPlugin v1
    [TestPlugin] Disabled!
    [Essentials] Enabling Essentials v2.13.1
    [Essentials: Using GroupManager based permission
    Here is my .yml:
    Code:
    name: TestPlugin
    main: name.testplugin.Main
    version: '1'
    author: [tooncool64]
    commands:
        hello:
            usage: /hello
            description: HelloMinecraft
    And my .class file:
    Code:java
    1. package name.testplugin;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.event.Listener;
    9.  
    10. public class Main extends JavaPlugin{
    11.  
    12. public void onEnable(){
    13. getLogger().info("Enabled!");
    14. }
    15.  
    16. public void onDisable(){
    17. getLogger().info("Disabled!");
    18. }
    19. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    20. Player player = (Player) sender;
    21. if(cmd.getName().equalsIgnoreCase("hello")){
    22. player.sendMessage(ChatColor.AQUA + "Hello Minecraft!");
    23. }
    24. return true;
    25. }
    26. }


    Please help!
     
  2. Offline

    Drkmaster83

    Are you sure it loads fine, without stack-traces? Because this looks like it should work.

    Edit: A few flaws, probably not the cause.
    • 'author' should not be followed by '[]', as it only requires one String.
    • 'version' shouldn't necessarily be in single quotes, then again, I haven't seen it like that before.
     
  3. Offline

    tooncool64

    Drkmaster83
    Ya, it loads fine, but then it automatically disables.
    EDIT:
    If the .yml was incorrect, it would probably show in the stack trace.
     
  4. Offline

    Drkmaster83

    Is there any other plugins other than Essentials?
     
  5. Offline

    kakaruso

    yes if you use only author it should be author: name without [] as Drkmaster83 said before and the rest of the code looks like right... try changing that in plugin.yml and then say us if your command works
     
  6. Offline

    Europia79

    tooncool64

    stop your server

    delete your server.log

    start your server

    open up your server.log

    and copy the contents

    post it on pastebin

    and post a link to your pastebin server.log

    Normally, the startup error will give an indication to what's wrong.

    I mean, i see your namespace is wrong... But I thought only "org.bukkit" namespaces would cause problems ? Maybe bukkit thinks your namespace is too short, or improperly formatted. Maybe try

    Code:
    main: mc.tooncool64.testplugin.Main
    Code:java
    1. package mc.tooncool64.testplugin;
     
  7. Offline

    tooncool64

    Yes, i have a hole bunch, i just excerpted that from my log.
    Drkmaster83
    kakaruso
    Trying that right now!
     
  8. Offline

    kakaruso

    that's true normally when plugin.yml has errors, plugin does not work... but is so strange this.. let me checking your code.
     
  9. Offline

    Europia79

    Drkmaster83

    for mine, i have
    Code:
    authors: [Europia79]
    but mine is plural. His is singular.
     
  10. Offline

    kakaruso

    Europia79 that methods works too i use it on all of my plugins due sometimes add testers or helpers there
     
  11. Offline

    Drkmaster83

    Yes, the plural form requires the '[]' to indicate that there's multiple Strings, and to split at a comma. However, this is singular and only requires one String.
     
  12. Offline

    tooncool64

  13. Offline

    kakaruso

    tooncool64 your code is right, is a simple command but i dont know what's the reason for it does not work.

    okey man author is your problem put author: tooncool64

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

    Drew1080

    tooncool64
    Your trying to execute the command through the console yet you are casting a Player to your sender in your command. Do an instanceof Player check first.
     
  15. Offline

    Drkmaster83

    You're kidding me.

    I was thinking you were doing it as a player since you had force-casted the player object even before the if-statement involving the command was made.
     
  16. Offline

    tooncool64

    kakaruso
    Um, i am trying that now.
    My problem is my plugin automatically Disables.

    Drew1080
    Drkmaster83
    I have been doing on minecraft and not through my console.

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

    kakaruso

    yes if you are trying to use the command via console, u will get an error due you are saying player is the sender and others senders go out.
    you can use sender.sendMessage for all the sender or as Drew1080 said using instanceof Player
     
  18. Offline

    Drew1080

    tooncool64
    Code:
     Unexpected exception while parsing console command "hello"
    org.bukkit.command.CommandException: Unhandled exception executing command 'hello' in plugin TestPlugin v1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchCommand(CraftServer.java:696) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchServerCommand(CraftServer.java:683) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.DedicatedServer.ax(DedicatedServer.java:286) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:251) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:548) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:459) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R2.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
            at name.testplugin.Main.onCommand(Main.java:19) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            ... 8 more
     
  19. Offline

    kakaruso

    what version are you using for compile it? and what version is you test server? maybe... i don't know as i said before is so strange.
     
  20. Offline

    Drkmaster83

    Have you tried doing the command while it's disabled?

    Okay, then that problem is old, just make sure you're doing it while in-game for now.
     
  21. Offline

    Europia79

    tooncool64

    Don't post the console. The server.log is easier to read.

    It was very hard to read, but it looks like you're not checking that the CommandSender is actually a player before casting sender to player.

    Here's the correct code:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("hello")){
    3. sender.sendMessage(ChatColor.AQUA + "Hello Minecraft!");
    4. }
    5. return true;
    6. }
     
  22. Offline

    kakaruso

    delete this and change:

    Code:java
    1. Player player = (Player) sender; // DELETE
    2. if(cmd.getName().equalsIgnoreCase("hello")){
    3. sender.sendMessage(ChatColor.AQUA + "Hello Minecraft!");//change


    for get avalible commands in console and in game
     
  23. Offline

    tooncool64

    Drew1080
    I know, i found that out the hard way XD.
    When i do /hello on minecraft, all that pops up is /hello and not Hello Minecraft!
    And the main problem is that it automatically disables when it enables
     
  24. Offline

    Europia79

    tooncool64

    stop your server. Delete your server.log, start your server, and post a the server.log

    Also, did you change the author to authors ? Or get rid of the brackets ?
     
  25. Offline

    Drkmaster83

    Perhaps it doesn't really disable, rather you have your messages mixed up? Try removing the 'usage' line from the plugin.yml for the command and then try the command.
     
  26. Offline

    tooncool64

    Europia79
    KK Doing it
    Drkmaster83
    I did it and now testing it out

    Ok. Pastebin link:
    http://pastebin.com/vvgt0esj
    Drkmaster83
    Still i got an error,
    Here is my new .class file:
    Code:java
    1. package name.testplugin;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.event.Listener;
    8.  
    9. public class Main extends JavaPlugin{
    10.  
    11. public void onEnable(){
    12. getLogger().info("Enabled!");
    13. }
    14.  
    15. public void onDisable(){
    16. getLogger().info("Disabled!");
    17. }
    18. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    19. if(cmd.getName().equalsIgnoreCase("hello")){
    20. sender.sendMessage("Hello Minecraft!");
    21. }
    22. return true;
    23. }
    24. }


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

    Drkmaster83

    Impossible... What's the error? The pastebin that you gave me?
     
  28. Offline

    tooncool64

    Oops,
    I combined to logs together!
    Ignore the first one!
    Drkmaster83
     
  29. Offline

    Drew1080

    tooncool64
    Well according to the stacktrace even the second one you are still casting a Player object to the sender when the sender is a console.

    Build your project again as a jar and make sure you are running that file, and not another one.
     
  30. Offline

    tooncool64

    Drew1080
    If you look at my new .class file, there shouldnt be an error!
     
Thread Status:
Not open for further replies.

Share This Page