Trying to broadcast text when command used, very confused

Discussion in 'Plugin Development' started by Lanuk, Nov 29, 2011.

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

    Lanuk

    Hello, I am pretty new to java but really want to get my first, simple bukkit plugin done but am having problems. My plugin is basically supposed to broadcast text when a command is used. I was also wondering if I could make it so that if a command from a different plugin is used, then broadcast certain text without having to peek into that plugins code somehow. Anywho, here is my code. I am probably missing a lot of essential things, sorry XD

    Code:
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class CommandWarning extends JavaPlugin {
    
        Logger log = Logger.getLogger("Minecraft");
    
        @Override
        public void onDisable() {
            log.info("CommandWarning has been disabled!");
        }
    
        @Override
        public void onEnable() {
            log.info("CommandWarning has been enabled!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("basic")){
                Server server = Bukkit.getServer();
                server.broadcastMessage("testing123");
                return true;
            }
            return false;
        }
    
    
    }
    
    And my yml file:

    Code:
    name: CommandWarning
    main: me.Lanuk.CommandWarning.CommandWarning
    version: 0.1
    commands:
       basic:
          usage: /test
          description: Test.
    
       
    I am getting a long error in the log when I try using my plugin (I am pretty sure I exported it to a jar file correctly). I can post that error if needed, but my mistake was probably an obvious one. Thanks in advance!
     
  2. Offline

    xpansive

    Yep, error please
     
  3. Offline

    Daniel Heppner

    That's not what he's trying to do.

    OP: Give us the error, please.
     
  4. :)
     
  5. Offline

    Daniel Heppner

    Oh. Derp. Sorry.
     
    r3Fuze likes this.
  6. Offline

    Lanuk

    Ok heres the error:

    Code:
    [SEVERE] Could not load 'plugins\CommandWarning.jar' in folder 'plugins':
    java.lang.ClassNotFoundException: me.Lanuk.CommandWarning.CommandWarning
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:36)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:24)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:170)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:215)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:136)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:141)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:117)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:141)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:388)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    I think what might be wrong is something with the package and class I made in eclipse while trying to follow the surprisingly easy to follow guide on how to make a plugin. I basically made the java project folder, inside it created a package called "me.Lanuk.CommandWarning", but instead of creating a class with my program inside of that package, I made it in my default package. I made my yml file by right clicking the project folder and making a new file. Is this all correct?

    Also you said I would need a PlayerCommandPreprocessEvent to do the thing with commands from other plugins... what does that even mean... I clicked the link but am not sure at all what to do. I guess thats just pushing my very limited knowledge of java a bit too far XD

    EDIT: I tried putting my class file in my created package (me.Lanuk.CommandWarning) and it still shows the same error
     
  7. Offline

    herghost

    hmm try this in your config.yml

    main: me.Lanuk.CommandWarning
    instead of
    main: me.Lanuk.CommandWarning.CommandWarning
     
  8. Offline

    Lanuk

    No luck, still getting the same error :(
     
  9. Offline

    Perdog

    What is the name of your main class?
     
  10. Offline

    halley

    In your plugin.yml, you state:

    Code:
    main: me.Lanuk.CommandWarning.CommandWarning
    
    So your main class should be called CommandWarning, and it should state above the class that it is in package me.Lanuk.CommandWarning, and the file should be exactly named me/Lanuk/CommandWarning/CommandWarning.java - nothing else.

    If you're using Eclipse, the folders above are usually nestled inside a src folder, which is okay.

    Note how the directory structure matches the package name and class name. Also note that the directories and filenames should have EXACTLY the same capitalization that you see here. Windows is often sloppy about filenames-- it may find the file even if you specify "comMAndWarnING.JAVA" but the java compiler will not be so forgiving.
     
  11. Offline

    Deathmarine

    Also one thing I noticed is that the command your trying to use in the plugin.yml is "test", or is it "basic". Might I suggest to change from /test to /<command>.

    Edit: also I would use this.getServer().broadcastMessage("ect");
    Obviously after you get you names figured out., but hey we all have to start somewhere.

    Edit: Alright so your moving your class around from packages. Think of bukkit like this... in the plugin.yml your laying the path for bukkit to find the class you made. if it can't find the class it will throw an exception hince (ClassNotFound Exception) you package must be me.lanuk.commandwarning. Remember java is picky about capitalization as well as the plugin.yml must say the exact same thing plus the class files name. Which just about everyone said the exact same thing as well.... oh well.
     
  12. Offline

    Lanuk

    I am still not sure what im doing wrong with the names though :(

    My class is named CommandWarning, in the YML it is called CommandWarning, I have this line above all my imports in my class:

    package me.Lanuk.CommandWarning;

    showing that the class IS in that package. I don't have any capitalization errors... so what am I doing wrong?

    EDIT: Alright, I think it may have been a tab or something in the YML file, because now I am getting a different error that looks like this:
    Code:
    [SEVERE] null loading CommandWarning v0.1 (Is it up to date?)
    java.lang.NullPointerException
        at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:26)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:273)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:176)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:159)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:337)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:324)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:161)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:388)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    2011-12-01 15:11:05 [INFO] Server permissions file permissions.yml is empty, ignoring it
    Double Edit: I fixed the error above and am now back to the original error.. o.o
     
  13. Offline

    halley

    When packaging your JAR file, do you include that class file? (In Eclipse, in the Jar Exporter, you put a checkmark on the .java file to include its .class file(s).)

    As a test, copy the Jar somewhere else and unpack it-- it should have the .yml and .class files in a suitable structure.
     
  14. Offline

    Lanuk

    Here is a copy of my project folder if anyone would be kind enough to take a loot at it
     

    Attached Files:

  15. Offline

    CainFoool

    There should be something like:
    package me.lanuk.CommandWarning.bblabladsfdsfsd

    at the very top.
     
  16. Offline

    Lanuk

    That may be my problem, as I am not sure how to "put a checkmark on the .java file". I tried extacting my jar file and it came up with my plugin.yml file and a META-INF folder. Basically what I do in eclipse is I checkmark the yml file, dont checkmark the .classpath or the .project. When I checkmark the YML it checkmarks my project folder with a blue box, and inside the src which contains my package is checkmarked.

    In my class file? There is.

    although, it looks like this: package me.Lanuk.CommandWarning;

    should I change it to this? package me.Lanuk.CommandWarning.CommandWarning;

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

    halley

    Per your #17, that's the problem. You want a checkbox on the src/me/Lanuk/CommandWarning package in that tree as well. Then re-examine the resulting Jar. If you have no .class file, that's the whole reason for the error message "class not found."

    I can take a screenshot later when I'm at my desk, if you want.

    Per your #18, no, see my #11 in this thread. Package is "all but the last part" of your fully qualified class name.
     
  18. Offline

    CainFoool

    [​IMG]
    It should be similiar to that.
     
  19. Offline

    Lanuk

    I am so confused, a screen shot would be helpful. The screenshot posted above by CainFoool made me get another error in the log stating that the jar did not contain the yml file even though I checked it. I did make sure to double click the project folder (in his case cConomy) and check src inside which contained my package.
     
  20. Offline

    Perdog

    Your using eclipse right? Do you have saros?
     
  21. Offline

    Lanuk

    I am using eclipse, but do not know what saros is :p
     
  22. Offline

    Perdog

    Its a plugin for eclipse that lets people work on code together, and I think you can screen share with it, if you get it I could watch you export it to make sure its doing everything right and look at the code for you
     
  23. Offline

    halley

    Click the little + next to the folder on the left half. A whole world opens up to you there...
     
  24. Offline

    dakoslug

    Lol did nobody notice the porn XD.
     
  25. Offline

    CainFoool

    It says pom.
    It's a file required if your project is Maven. (Which in case, mines is)
    http://ci.blockout.co.cc:8080 (My Repo) uses Maven
     
    Kohle likes this.
  26. Offline

    dakoslug

    I'm blind (or I was trolling)
     
  27. Offline

    Lanuk

    Like I said, I did, and I checked the src folder inside it. Ill get that saros thing if it isnt too late
     
  28. Offline

    Lanuk

    Alright, well I got saros if anyone would be kind enough to take a quick peek at what I am doing. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page