我正在爲服務器製作一個具有基本命令的插件,並且我已經放入了一些正常工作的事件。但是當我嘗試添加命令時,它不起作用。 (在你問之前,我用一個簡單的sendMessage替換了onCommand部分的所有內容,並且它什麼都不做)。當我執行命令時,它只是告訴我我已經在plugin.yml中使用的用法。bukkit命令識別n
這裏是我的代碼:對不起,這是很長的
package com.pepsi.core;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener {
@Override
public void onEnable() {
Bukkit.getLogger().info("PepsiCore >> Enabled!");
Bukkit.getServer().getPluginManager().registerEvents(this, this);
getConfig().options().copyDefaults(true);
saveConfig();
}
@Override
public void onDisable() {
Bukkit.getLogger().info("PepsiCore >> Disabled!");
}
public boolean onCommand(Command cmd, CommandSender sender, String cmdLbl, String[] args) {
if (args.length == 0) {
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eNot enough arguments! Use &6/pcore help &e to see a list of commands!"));
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("help")) {
sender.sendMessage(Util.transMsg("&8--------------------<&6&lPepsiCore&8>--------------------"));
sender.sendMessage(Util.transMsg("&6/pcore help &8>> &eDisplays the help page"));
sender.sendMessage(Util.transMsg("&6/pcore info &8>> &eDisplays the plugin info page"));
sender.sendMessage(Util.transMsg("&6/pcore ranks &8>> &eDisplays all the ranks"));
sender.sendMessage(Util.transMsg("&6/pcore setrank <player> <rank> &8>> &eDisplays all the ranks"));
sender.sendMessage(Util.transMsg("&8--------------------<&6&lPepsiCore&8>--------------------"));
return true;
}
if (args[0].equalsIgnoreCase("info")) {
sender.sendMessage(Util.transMsg("&8--------------------<&6&lPepsiCore&8>--------------------"));
sender.sendMessage(Util.transMsg("&ePepsiCore version &61.0.0-BETA"));
sender.sendMessage(Util.transMsg("&eDeveloped by &6P3pi &efor &6Project: Infernal"));
sender.sendMessage(Util.transMsg("&8--------------------<&6&lPepsiCore&8>--------------------"));
return true;
}
if (args[0].equalsIgnoreCase("ranks")) {
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eRanks: &6guest&e, &6gold&e, &6diamond&e, &6emerald&e, &6yt&e, &6staff&e, &6developer&e, &6owner"));
return false;
}
if (args[0].equalsIgnoreCase("setrank")) {
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eNot enough arguments! Use &6/pcore help&e to see a list of commands!"));
return false;
}
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eInvalid arguments! Use &6/pcore help&e to see a list of commands!"));
return false;
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("setrank")) {
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eNot enough arguments! Use &6/pcore help&e to see a list of commands!"));
return false;
}
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eInvalid arguments! Use &6/pcore help&e to see a list of commands!"));
return false;
}
if (args.length == 3) {
if (args[0].equalsIgnoreCase("setrank")) {
Player t = Bukkit.getServer().getPlayer(args[1]);
if (t == null) {
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eThe player &6" + args[1] + " &eis not online at the moment!"));
return false;
}
String uuid = t.getUniqueId().toString();
String rank = args[2];
if (rank == ("guest")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("gold")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("diamond")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("emerald")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("yt")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("staff")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("developer")) { getConfig().set("ranks." + uuid, rank); }
else if (rank == ("owner")) { getConfig().set("ranks." + uuid, rank); }
else { sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eThe rank &6" + rank + " &e does not exist! Use &6/pcore ranks &eto see a list of ranks!")); }
}
sender.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eInvalid arguments! Use &6/pcore help&e to see a list of commands!"));
return false;
}
return true;
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
String uuid = p.getUniqueId().toString();
String name = p.getName();
String msg = e.getMessage();
String rank = (String) getConfig().get("ranks." + uuid);
if (rank == "guest") { e.setFormat(Util.transMsg("&fGuest &7&l" + name + " &8>> &f" + msg)); }
else if (rank == "gold") { e.setFormat(Util.transMsg("&eGold &6&l" + name + " &8>> &e" + msg)); }
else if (rank == "diamond") { e.setFormat(Util.transMsg("&bDiamond &3&l" + name + " &8>> &b" + msg)); }
else if (rank == "emerald") { e.setFormat(Util.transMsg("&aEmerald &2&l" + name + " &8>> &a" + msg)); }
else if (rank == "yt") { e.setFormat(Util.transMsg("&dYouTuber &5&l" + name + " &8>> &d" + msg)); }
else if (rank == "staff") { e.setFormat(Util.transMsg("&9Staff &1&l" + name + " &8>> &9" + msg)); }
else if (rank == "developer") { e.setFormat(Util.transMsg("&cDeveloper &4&l" + name + " &8>> &c" + msg)); }
else if (rank == "owner") { e.setFormat(Util.transMsg("&cOwner &4&l" + name + " &8>> &c" + msg)); }
else { e.setCancelled(true); p.sendMessage(Util.transMsg("&e<!> &6&lPepsiCore &8>> &eYour rank seems to be broken! Please let a member of staff know!")); }
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
String uuid = p.getUniqueId().toString();
if (p.hasPlayedBefore() == false) {
getConfig().set("ranks." + uuid, "guest");
saveConfig();
return;
}
}
}
這裏是我plugin.yml:
name: PepsiCore
author: P3pi
version: 1.0.3
main: com.pepsi.core.Main
commands:
pcore:
description: Core command
usage: /pcore
pepsicore:
description: Core command
usage: /pepsicore
感謝您的幫助
我已經完成了你所說的,它仍然具有完全相同的問題... onCommand部分中的所有返回錯誤現在都返回true並且仍然不起作用,並且還試圖在底部返回true假,其餘返回true ....請幫忙嗎? – graphicalcake95
我也注意到,對於你的onCommand()參數,你有'Command cmd,CommandSender sender,String cmdLbl,String [] args'。使用參數的正確方法是'public boolean onCommand(CommandSender sender,Command cmd,String commandLabel,String [] args){}'。實際上並不知道這是否有助於解決您的主要問題,但我想指出。 – Vlexing
讓他們都返回true,它應該隱藏消息 – Squiddie