Hey guys, I am making a plugin with many different commands and I tried making a command per class. But it doesn't work. I type the command in game thats inside its own class and nothing happens, no lines pop up or anything, and the console shoes no errors. Here's my class code: Code:java public class CommandCC extends Main { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] Args) { if(sender instanceof Player) { Player player = (Player) sender; // PLUGIN PREFIX String Pluginprefix = "[Prefix] "; // START COMMANDS // CC if(cmd.getName().equalsIgnoreCase("cc")) { code code code; } Bukkit.broadcastMessage(Pluginprefix + "Chats cleared!"); } } return false; }} I have the same public boolean in my main class (Main.java) and yeah, I was wondering if anyone could shed some light on this problem, thanks.
Ok, so you have your class main. Great. Now, let's say you had another class, called oranges. In our oranges, we would make it say this: public class oranges implements CommandExecutor { Then do your ONCOMMAND method here. Now, go back to your main class and put this: getCommand("oranges").setExecutor(new oranges()); and add the command to your plugin.yml
Mr360zack This is incorrect The class listening for commands should implement CommandExecutor and not Listener
Mr360zack FlareLine Ok, I added getCommand("CommandCC").setExecutor(new CommandCC()); to my Main.java class. (By the way, my other /cc class is CommandCC. And these are underlined in red: getCommand("CommandCC").setExecutor(new CommandCC()); The getCommand error is: "Return type for the method is missing".
You need to put the getCommand inside of the onEnable Also getCommand("THIS") - this = the name of the command, not the class name.
FlareLine Code:java package net.minermax7.manycommands; import org.bukkit.Bukkit;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player; public class CommandCC extends Main implements CommandExecutor{ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] Args) { if(sender instanceof Player) { Player player = (Player) sender; // PLUGIN PREFIX [ManyCommands] String Pluginprefix = "§3§l[§2§lMany§2§lCommands§3§l] "; // START COMMANDS // CC if(cmd.getName().equalsIgnoreCase("cc")) { code code code; } } return false; }} Main.java class: Code:java package net.minermax7.manycommands; import java.util.Arrays; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.GameMode;import org.bukkit.Location;import org.bukkit.Material;//import org.bukkit.Sound;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Arrow;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect; //TODO/* kickall* mute* godmode* unban* ****ADD IF ARGS == 1! (/heal [name]) (/msg [name] message)*****/public class Main extends JavaPlugin implements Listener { public void onEnable() { getServer().getPluginManager().registerEvents(this, this); getLogger().info("ManyCommands has been enabled!"); } public void onDisable() { getLogger().info("ManyCommands has been disabled."); } private Location spawn = null; //CLASS REFERENCES getCommand("CommandCC").setExecutor(new CommandCC()); public boolean onCommand(CommandSender sender, Command cmd, String label, String[] Args) { if(sender instanceof Player) { Player player = (Player) sender; Many more command down but doubt they will be needed.
I have changed it and it's in onEnable(). When I enter the command nothing happens... And the server gets an error when I load the plugin up.
do you have the file 2 time in your plugins folder? like ManyCommands(1).jar and ManyCommands.jar also i don't think this would be the problem but try it //edit: i tried to install a plugin 2 times and it worked... no error Try installing another bukkit build EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You cannot extend Main in your command class, because it extends JavaPlugins, and thus tries to create another Main-class Plugin. That's the error right there (I know since I did a silly mistake like that as well)
FlareLine Your class ends up being an extension of JavaPlugin, which should only be initialized once, which is through Bukkit. Since he tried to make a new instance of the class that extends Main (which extends JavaPlugin), it threw the error, because you tried to create a new instance of the JavaPlugin, At least, thats how I interpret it. You'd have to go through Bukkit source to find the "in-depth" reason the error is thrown EDIT: Link to where its thrown