Reputation: 43
My spigot plugin doesn't work. On the console, it says the plugin is enabled but i can't run the command in the plugin. Pls help.
This is the main code Plugin.java
package lol.quacnooblol.mypvpplugin;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Plugin extends JavaPlugin{
@Override
public void onEnable() {
Bukkit.getServer().getLogger().info("Plugin Enabled");
}
@Override
public void onDisable() {
Bukkit.getServer().getLogger().info("Plugin Disabled");
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage("You ran this command on the console");
}
Player player = (Player) sender;
if(cmd.getName().equalsIgnoreCase("test")) {
player.sendMessage("You ran the test command in game.");
return true;
}
return true;
}
}
This is the plugin.yml
name: Plugin
version: 0.1
main: lol.quacnooblol.mypvpplugin.Plugin
author: QuacNoobLoL
description: A pvp plugin
command:
test:
usage: /<command>
description: A test command
Upvotes: 1
Views: 1274
Reputation: 1
in your Plugin.yml you need to use three spaces and not tab
here is the fixed file:
name: Plugin
version: 0.1
main: lol.quacnooblol.mypvpplugin.Plugin
author: QuacNoobLoL
description: A pvp plugin
commands:
test:
usage: /<command>
description: A test command
And your Plugin.java onCommand boolean needs the @Override annotation like this:
@Override
public boolean onCommand(CommandSender, Command cmd, String commandLabel, String[] args) {
if(cmd.getName().equalsIgnoreCase("test")){
if(!(sender instanceof Player)){
sender.sendMessage("You ran this command on the console");
}
Player player = (Player)sender;
if(sender instanceof Player){
player.sendMessage("You ran the test command in game.");
}
return true;
}
}
this should work
Upvotes: 0
Reputation:
Change the plugin.yml command
to commands
In the future please refer to the plugin.yml documentation and remember even a single letter can break your code!
Upvotes: 8