【问题标题】:My commands in spigot plugin doesn't work我在 spigot 插件中的命令不起作用
【发布时间】:2018-03-14 11:04:04
【问题描述】:

我的 spigot 插件不起作用。在控制台上,它说插件已启用,但我无法在插件中运行命令。请帮忙。

这是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;
    }
}

这是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

【问题讨论】:

    标签: java plugins bukkit


    【解决方案1】:

    将plugin.yml command改为commands

    以后请参考plugin.yml documentation,记住即使一个字母也能破解你的密码!

    【讨论】:

      【解决方案2】:

      在您的 Plugin.yml 中,您需要使用三个空格而不是制表符

      这里是固定文件:

      name: Plugin
      version: 0.1
      main: lol.quacnooblol.mypvpplugin.Plugin
      author: QuacNoobLoL
      description: A pvp plugin
      commands:
         test:
         usage: /<command>
         description: A test command
      

      而您的 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;
         }   
      }
      

      这应该可以工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-27
        相关资源
        最近更新 更多