2015-01-16 71 views
-2
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); 
    } 
}  

}按需語法錯誤bukkit插件

//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。 有語法錯誤百出,通過了與公共布爾按需啓動( 它口口聲聲說我應該更換某些行與(,)■括號,雖然我很放心,這是假的。

  • 它不會加載,它不斷告訴我,我有一個無效的plugin.yml,這是對我的下面代碼不斷告訴我我有一個不好的描述,儘管它很好(或者我認爲是)。

  • 我仍然試圖嘗試事件,所以如果你有任何提示,那將不勝感激:)。我試圖使用AsyncPlayerChatEvent,我想我需要實現監聽器。

  • +0

    我建議在每個if語句的末尾添加'return false;'或'return true;'。它不會在日食中顯示,但它會導致我相信的問題。這和我所知道的一樣多。 – NealC

    回答

    -1

    你並不需要列出每個參數可能在plugin.yml你的主要命令。這應該不是這個樣子: commands: sc: description: whatever you want players to see in /help

    -1

    你忘了做:

    usage: /<command> 
    

    在你plugin.yml。

    +0

    這沒有做任何事情。這是可選的使用 – JarFile

    2

    您的類文件似乎有巨大的語法錯誤。

    1.)您的onCommand布爾值是在您的onEnable方法內將它移到您的onEnable方法之外。

    2.)您的onCommand布爾值也返回false使它根本不能返回。

    3)你在你的插件陽明語法似乎也關閉,嘗試將其更改爲:

    //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您主要命令,在這種情況下是發誓者。將其更改爲:

    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); 
    

    這將註冊您的活動。