bukkit聊天可点击按钮

egmofgnx  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(387)

我实际上是在编写一个插件,在一个命令中它会提示一条确认消息,我想点击一个按钮(在聊天文本上)来确认和取消。我不喜欢复制和粘贴别人的代码,也不想使用别人的类。我试图使用文本组件,但我不能使它工作。这是命令码

package myPackage;

import java.awt.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class InfoCommand implements CommandExecutor {

    public TextComponent TextComponent;
    @Override
    public boolean onCommand(CommandSender sender, Command cmnd, String alias, String[] args) {
        if (!(sender instanceof Player)) {
            return false;
        }
        Player player = (Player) sender;
        player.sendMessage(new String[] {
                            "Confirmation message.",
                            "Do you want to confirm?"});
        TextComponent message = new TextComponent ("Yes");
        message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/command"));
        return true;
    }            
}

它告诉我3个错误: TextComponent(String) is not public in TextComponent; cannot be accesed from outside package (在我定义textcomponent的行中) Cannot find symbol (在clickevent行中) Package ClickEvent does not exist (在clickevent行中)
如何解决错误?有一个更简单的方法来做一个可点击的按钮(没有其他类或复制/粘贴)?

camsedfj

camsedfj1#

你有两个问题。
你缺少依赖关系。将以下依赖项添加到pom.xml:

<dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version-->
        <type>jar</type>
        <scope>provided</scope>
</dependency>

您已导入 java.awt.TextComponent 在你的 InfoCommand 同学们,这是错误的。因此,请删除该导入并添加以下内容:

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;

相关问题