无法在基本类型boolean上调用equalsIgnoreCase()

时间:2013-11-02 16:10:34

标签: java eclipse plugins bukkit

我正在为bukkit服务器创建一个插件,一个antiswear,但我试图不让它区分大小写,我该怎么做?代码:

package me.Lorenzo.AntiSwear;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
            for(String word : e.getMessage().split(" ")){
                    if(getConfig().getStringList("bannedwords").contains(word)){
                                    e.setCancelled(true);
                                    e.getPlayer().sendMessage(ChatColor.DARK_RED + "Please don't use that sort of language!");
                    }
            }
    }





    public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }

}

2 个答案:

答案 0 :(得分:0)

  1. onEnable中,确保所有bannedwords均为小写。

  2. onPlayerChat中,使用e.getMessage().toLowerCase().split(" ")代替e.getMessage().split(" ")

答案 1 :(得分:0)

如何添加toLowerCase():

if(getConfig().getStringList("bannedwords").contains(word.toLowerCase())){