简体   繁体   English

我在 spigot 插件中的命令不起作用

[英]My commands in spigot plugin doesn't work

My spigot plugin doesn't work.我的 spigot 插件不工作。 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这是主要代码 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这是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

Change the plugin.yml command to commands将 plugin.yml command改为commands

In the future please refer to the plugin.yml documentation and remember even a single letter can break your code!以后请参考plugin.yml 文档,记住即使是一个字母也能破坏你的代码!

in your Plugin.yml you need to use three spaces and not tab在您的 Plugin.yml 中,您需要使用三个空格而不是制表符

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:你的 Plugin.java onCommand 布尔值需要像这样的 @Override 注释:

@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这应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM