私はサーバーに不可欠なコマンドを使ってプラグインを作成していますが、うまく動作しているいくつかのイベントを入れました。しかし、コマンドを追加しようとすると動作しません。 (質問する前に、私はonCommandセクションのすべてを単純なsendMessageに置き換えました。何もしません)。コマンドを実行すると、plugin.ymlに入れた使い方がわかります。ここでbukkitコマンドが認識されました。
は私のコードです:申し訳ありませんが、それは
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です:ヘルプ
私はあなたが言ったことをやった、それはまだ正確に同じ問題を持っている...オンデマンドセクション内のすべての戻りfalsesは今trueを返し、まだ働いていない、とも返却され、右下部にあるものにしようとしました偽と残りは真実を返す....助けてください? – graphicalcake95
また、あなたのonCommand()argsには、コマンドcmd、CommandSender sender、String cmdLbl、String [] args'があることに気付きました。 argsを持つ正しい方法は 'public boolean onCommand(CommandSender sender、Command cmd、String commandLabel、String [] args){}'です。それがあなたの主な問題に役立つかどうか実際には知りませんが、私はそれを指摘したいと思います。 – Vlexing
それらのすべてが真実に戻り、メッセージを隠すはずです – Squiddie