gpt4 book ai didi

java - 有没有办法在没有 AsyncPlayerChatEvent 的情况下捕获玩家聊天输入?

转载 作者:行者123 更新时间:2023-12-02 02:18:58 26 4
gpt4 key购买 nike

我再次编写另一个银行系统插件,但这次是使用 ATM。我正在尝试弄清楚如何在点击该选项后让玩家进行聊天输入,以防止点击 100 次将 50,000 美元存入银行帐户。

我正在使用 Paper-Spigot 1.14.4 编写此插件,并尝试了以下步骤:

  • 一个AsyncPlayerChatEvent作为一个单独的类,仅当我使用插件管理器注册事件时才会激活:
Bukkit.getPluginManager().registerEvents(new ChatListener(), Main.getPlugin());
  • 创建 private AsyncPlayerChatEvent变量e使用 get- 和 set-method,并在需要时在方法中调用它。
String input = getChat().getMessage();

我当前的chatListener()方法:

public void chatListener(Inventory inv, Player pl) {
pl.closeInventory();
pl.sendMessage("§6Please enter your amount:");
String input = getChat().getMessage();
if(input.matches("[0-9]+")) {
pl.openInventory(inv);
inv.setItem(0, new ItemStack(Material.AIR));
inv.setItem(0, CustomHeads.customHead(CustomHeads.BITCOIN,
input));
} else {
pl.sendMessage("§cPlease enter only numeric characters!");
}
}

AsyncPlayerChatEvent获取方法:

public AsyncPlayerChatEvent getChat() {
return chat;
}

我希望玩家的消息保存在input内变量,出现消息“请输入您的金额:”后。

当我创建System.out.println(input)时,控制台没有显示任何内容,既没有错误也没有任何警告。

最佳答案

创建一个 AsyncPlayerChatEvent 和一个 public static ArrayList

ExampleChatEvent.class

public static ArrayList<Player> waitingForAmountPlayers = new ArrayList<>();

public void onChat(AsyncPlayerChatEvent e) {

Player p = e.getPlayer();

if (waitingForAmountPlayers.indexOf(p) != -1) {

//
// YOUR CODE
//

waitingForAmountPlayers.remove(p);

}

}

当您想在聊天中输入玩家金额时,不要忘记将玩家添加到 waitingForAmountPlayers (ExampleChatEvent.waitingForAmountPlayers.add(p);) .

关于java - 有没有办法在没有 AsyncPlayerChatEvent 的情况下捕获玩家聊天输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57286427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com