-1

Hopefully you guys can help me fix this. I'm sorta new to Java, and very new to the BukkitAPI. I learn best by just going ahead and attempting projects, and then doing tons of research when I can't figure something out.

I've looked all around, and I cannot figure out why this isn't working. I'm attempting to make a plugin, and am utilizing multiple classes for organization and cleanliness. I'm typing everything how it should be typed, and have been going off of this tutorial here. It is a bit old, so some things might have changed. The problem is, when I run the command, I get no errors yet it just doesn't do anything. It says "Alj23 issued the server command: /hello (which is my command temporary until I fix this) in the console, yet nothing happens. No message in chat, no nothing. No errors in the console. It's suppose to send the player who issued the command a message saying "Hello there!" (also temporary for right now.) I just don't know why it works.

I'm still learning, so I'm most likely doing something blatantly wrong. I also might be following bad practices or doing unneeded things, so if so, it would be amazing if you could point them out.

My main class:

package me.Alj23.RPGClasses;

import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

public class RPGClassesMain extends JavaPlugin implements Listener

{
public void OnEnable()
{
    this.getCommand("hello").setExecutor(new WarriorInfo(this));
}

public void OnDisable()
{

}

The class that executes the code for the command:

package me.Alj23.RPGClasses;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class WarriorInfo implements CommandExecutor
{
RPGClassesMain plugin;

public WarriorInfo (RPGClassesMain passedPlugin)
{
    this.plugin = passedPlugin;
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label,String[] arg3) 
{
    Player player = (Player) sender; 
    player.sendMessage("Hello there!");


return false
}

}

Plugin.yml:

 name: RPGClasses
 version: 1.0
 main: me.Alj23.RPGClasses.RPGClassesMain
 description: Choose beyond a wide scope of classes!
 commands:
 hello:
 description: placeholder!
  • Is that yaml file exactly as you have it? Check the spacing/alignment requirements. – Celeo Dec 01 '14 at 23:35
  • No. I had to do the four space indention to make it read as code. I have it formatted correctly in my actual plugin.yml, else it would have told me that I had a invalid plugin.yml, right? – austinj1022 Dec 01 '14 at 23:44
  • No, it would have registered no commands, that is a `NullPointerException` while accessing `Command.setExecutor(CommandExecutor)`. – spongebob Dec 02 '14 at 07:40

1 Answers1

4

Look at the OnEnable and OnDisable methods. According to Java conventions (and the Bukkit API), those methods should be named onEnable and onDisable, respectively. This misspelling caused your command to never be register in the first place.

Also, correct indentation is a must for YAML files. It should look like this:

name: RPGClasses
version: 1.0
main: me.Alj23.RPGClasses.RPGClassesMain
description: Choose beyond a wide scope of classes!
commands:
  hello:
    description: placeholder!
August
  • 12,410
  • 3
  • 35
  • 51
  • You are amazing! This worked. Thank you so much. I can't believe that it was just two capitalized "O" messing everything up. Such a miniscule thing that it was hard to notice in the frustration. Looked exactly the same. Question though, is OnEnable and onEnable two different things? Why did it not give me an error when I had it onEnable for the longest time? – austinj1022 Dec 01 '14 at 23:51
  • 1
    @austinj1022 It doesn't give you an error because misspelling a method is perfectly fine, from the compiler's perspective. This is a great lesson of [why you should use `@Override`](http://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why). The two methods are different because they are called at different phases of the program. Feel free to accept the answer if it helped! :) – August Dec 01 '14 at 23:55
  • Oh! I attempted to use @Override because that's what was being used in the video. It kept giving me an error when I did and told me to remove it. I never put two and two together that my method was misspelled. Thanks1 – austinj1022 Dec 01 '14 at 23:58