簡體   English   中英

Bukkit 插件不起作用?

[英]Bukkit plugin not working?

所以我最近嘗試為我的世界制作一個 bukkit 插件。 這個想法是,這只是一個測試插件,看看我是否可以做到,顯然我做不到。 這是我想出的代碼

package me.glowhoo.BlockChanger;  import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
    Bukkit.getLogger().info(this.getDescription().getName() +
            " has been enabled");
     }
@Override public void onDisable() {
    Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
    } 
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    /*command: /tpa Glowhoo
     * args.length = 1
     * args[0] = Glowhoo
     * command.getName() = tpa
     */
    if (cmd.getName().equalsIgnoreCase("message")){
        if(sender instanceof Player)
        {
            /*ComandSender sender-who sent the command
             * Command cmd- the command that was executed
             * String commandLabel-the command alias that was used
             * String[] args-array of additional arguments
             */
            sender.sendMessage(ChatColor.RED +"Hello player!");
        }else
        {
            sender.sendMessage(ChatColor.AQUA +"Hello console!");               
        }
     }
    return false;
   }
 } 

所以這個問題是,每當我加載服務器時,它都會說“BlockChanger已啟用”,但是當我嘗試鍵入它具有的唯一命令(消息)或/消息時,沒有任何反應並且它說是一個無法識別的命令,輸入 /help 獲取信息。 問題並沒有就此結束,每當我真正嘗試讓插件運行時,90% 的時間我都會遇到 plugin.yml 錯誤,我不完全理解,但是如果你們中的任何人對此問題有所了解, 請回答

我的 plugin.yml 文件在這里(注意:這個 plugin.yml 副本實際上有效,但命令本身無效。):

name: BlockChanger
version: 1.0
main: me.glowhoo.BlockChanger.BlockChanger
description: 
commands: 
message:
description: -no desc-
usage: /message

您的plugin.yml不正確。 您需要在commands下縮進message以定義節點。 目前, commands是一個無用的關鍵值。 將相關部分改成這樣:

commands: 
  message:
    usage: /message

這是將來的某個時間,但是如果您再次使用它,當您有命令時,您需要返回 true,否則它會告訴您這是一個不正確的命令,即使您的 .yml/.yaml 文件是設置正確。 因此,您需要執行以下操作才能在調用時注冊您的命令:

package me.glowhoo.BlockChanger;  import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
    Bukkit.getLogger().info(this.getDescription().getName() +
            " has been enabled");
     }
@Override public void onDisable() {
    Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
    } 
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    /*command: /tpa Glowhoo
     * args.length = 1
     * args[0] = Glowhoo
     * command.getName() = tpa
     */
    if (cmd.getName().equalsIgnoreCase("message")){
        if(sender instanceof Player)
        {
            /*ComandSender sender-who sent the command
             * Command cmd- the command that was executed
             * String commandLabel-the command alias that was used
             * String[] args-array of additional arguments
             */
            sender.sendMessage(ChatColor.RED +"Hello player!");
        }else
        {
            sender.sendMessage(ChatColor.AQUA +"Hello console!");               
        }
        return true;
     }
    return false;
   }
 }

您需要在 onEnable 方法中將此類注冊為命令執行器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM