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。 有語法錯誤百出,通過了與公共布爾按需啓動( 它口口聲聲說我應該更換某些行與(,)■括號,雖然我很放心,這是假的。
它不會加載,它不斷告訴我,我有一個無效的plugin.yml,這是對我的下面代碼不斷告訴我我有一個不好的描述,儘管它很好(或者我認爲是)。
我仍然試圖嘗試事件,所以如果你有任何提示,那將不勝感激:)。我試圖使用AsyncPlayerChatEvent,我想我需要實現監聽器。
我建議在每個if語句的末尾添加'return false;'或'return true;'。它不會在日食中顯示,但它會導致我相信的問題。這和我所知道的一樣多。 – NealC