onCommand语法错误bukkit插件

时间:2015-01-16 00:49:15

标签: java eclipse plugins minecraft bukkit

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,我想我需要实现监听器。

4 个答案:

答案 0 :(得分:2)

您的类文件中似乎存在巨大的语法错误。

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:

命令后:你也错了,你没有把你的所有参数放在 JUST 你的主命令,在这种情况下是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);

这将注册您的活动。

答案 1 :(得分:0)

由于你的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

答案 2 :(得分:-1)

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

答案 3 :(得分:-1)

你忘记了:

usage: /<command>

在你的plugin.yml。