作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我再次编写另一个银行系统插件,但这次是使用 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/
我是一名优秀的程序员,十分优秀!