【问题标题】:onCommand syntax error bukkit pluginonCommand 语法错误 bukkit 插件
【发布时间】:2015-03-14 13:37:33
【问题描述】:
package me.Nitsua.SwearCatcher;

import java.util.logging.Logger;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Event;



public class SwearCatcher extends JavaPlugin {
public final Logger logger = Logger.getLogger("Minecraft");
@SuppressWarnings("rawtypes")
public static SwearCatcher plugin;


@Override
public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " has been disabled!");
}

@Override
public void onEnable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
    PluginManager pm = getServer().getPluginManager();


    int count = 0;
    String[] id;
    String[] swear;
    String[] change;



    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        Player player = (Player) sender;


        if(commandLabel.equalsIgnoreCase("sc") || commandLabel.equalsIgnoreCase("swearcatcher")) {
            if (args.length == 0) {
                player.sendMessage("/sc <Swear> <Change>");
                player.sendMessage("/sc list");
                player.sendMessage("/sc remove <number>");
            }

            if (args.length == 1){
                if (args[0] == "list"){
                    for (int i=0; i = count; i++){
                        player.sendMessage(id[i] +swear[i] + change[i]);

                    }
                }
            }

            if (args.length== 2) {
                if (args[0] == "remove" && args[0] != "") {
                    id[args[1]] = 0;
                    swear[args[1]] = 0;
                    change[args[1]] = 0;    
                } 


                if (args[0] != "remove" && args[0] != "list"){
                count = count + 1;
                id[count] = id[count];
                swear[count] = swear[args[1]];
                change[count] = change[args[2]];
                }
            }
        }
        return false;   
    }
    @EventHandler
    public void playerchats(AsyncPlayerChatEvent event){
        event.setCancelled(true);
        chat = event.getMessage();

        for (i = 0, i = count;;) {
            chat = chat.replaceAll(swear[i], change[i]);
        }
        event.setMessage(chat);
    }
}       

}

 //plugin.yml
 name: SwearCatcher
 main: me.Bench3.SwearCatcher.SwearCatcher
 version: 1.0
 description: Pulls swear words from chat, and makes them better to read!
 main: me.Nitsua234.SwearCatcher.SwearCatcher
 author: Nitsua234

  commands:
   sc list:
     description: List all the swear words, their changes, and their id's.
   sc remove <swear id>:
     description: removes a swear from the list.
   sc <swear> <change>:
     description: replaces a swear with something nice.

我的问题: 1. 以 public Boolean onCommand( 它一直说我应该用 (,)s 替换某些括号,尽管我确信这是错误的。

  1. 它不会加载,它一直告诉我我有一个无效的 plugin.yml,它就在我的代码下方。它一直告诉我我有一个不好的描述,虽然它很好(或者我认为它是)。

  2. 我仍在尝试尝试事件,所以如果您有任何提示,将不胜感激:)。我尝试使用 AsyncPlayerChatEvent,我想我需要实现监听器。

【问题讨论】:

  • 我建议在每个 if 语句的末尾添加 return false;return true;。它没有出现在日食中,但我相信它会引起问题。我知道的就这么多了。

标签: java eclipse plugins minecraft bukkit


【解决方案1】:

你的类文件中似乎有很大的语法错误。

1.) 您的 onCommand 布尔值在您的 onEnable 方法内将它移到您的 onEnable 方法之外。

2.) 您的 onCommand 布尔值也返回 false 使其根本不返回。

3.) 您的插件 yml 中的语法似乎也关闭了,请尝试将其更改为:

 //plugin.yml
name: SwearCatcher
main: me.Bench3.SwearCatcher.SwearCatcher
version: 1.0
description: Pulls swear words from chat, and makes them better to read!
main: me.Nitsua234.SwearCatcher.SwearCatcher
author: Nitsua234
commands:

在命令之后:你也错了,你没有把所有的参数都放在这里只是你的主要命令,在这种情况下是 swearcatcher。改成:

commands:
  swearcatcher:
    description: List all the swear words, their changes, and their id's.
    aliases: [sc]

如果别名为 sc,当他们键入 /sc 时,命令也会运行。

4.) 除了您的事件之外,是的,您还需要实现一个监听器,不仅如此,您还需要注册它。要注册,请将其放入您的 onEnable

this.getServer().getPluginManager().registerEvents(this, this);

这将注册您的活动。

【讨论】:

    【解决方案2】:

    因为你的 plugin.yml 问题:

    commands:
    sc:
     description: List all the sc commands.
    

    “sc”是你的命令。其余的都是参数。

    在这里,您可以找到有关事件和类似内容所需的一切: http://jd.bukkit.org/rb/doxygen/df/d08/namespaceorg_1_1bukkit_1_1event.html

    【讨论】:

      【解决方案3】:

      你忘了做:

      usage: /<command>
      

      在你的 plugin.yml 中。

      【讨论】:

      • 那没有任何作用。这是可选的使用
      【解决方案4】:

      您不需要在plugin.yml 中列出您的主命令可能的每个参数。相反,它应该看起来像这样: commands: sc: description: whatever you want players to see in /help

      【讨论】:

        猜你喜欢
        • 2014-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-04
        • 2014-08-16
        • 2016-11-12
        • 1970-01-01
        • 2016-12-15
        相关资源
        最近更新 更多