gpt4 book ai didi

java - 如何仅点击一次库存项目

转载 作者:行者123 更新时间:2023-12-01 12:41:45 25 4
gpt4 key购买 nike

我正在尝试使用箱子 list 在《我的世界》中使用 Bukkit 来操纵用户 GUI,以便我的服务器工作人员可以更好地处理惩罚。我对 Java 相当陌生,因为我厌倦了现有的插件,因为它们不是我需要的功能。

我已将 GUI 与 InventoryClickEvent Hook ,因此每当玩家单击特定项目时,就会从玩家执行特定命令。但是,即使我立即取消事件以防止多次使用/mute 命令(示例),事件也不会立即取消,因此目标将被静音 2-3 次(因为工作人员正在单击该项目) .

即使事件没有立即取消,是否有办法只执行该命令一次?

这是代码的主要部分:

/**
* Applies the punishment when the player clicks on an item.
*
* @param e
*/
@EventHandler
public void ApplyPunishment(InventoryClickEvent e)
{
if (!e.getInventory().getName().equalsIgnoreCase(gui.getName())) return;
if (e.getCurrentItem().getItemMeta() == null) return;

this._player = (Player) e.getWhoClicked();

if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Modified/Hacked Client"))
{
e.setCancelled(true);
this._player.closeInventory();
PunishModifiedClient();
}

if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Chat Spam/Advertisement"))
{
e.setCancelled(true);
this._player.closeInventory();
PunishChatSpam();
}

if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Bug Exploitation/Glitch"))
{
e.setCancelled(true);
this._player.closeInventory();
PunishBugExploit();
}

if (e.getCurrentItem().getItemMeta().getDisplayName().contains("General/Other Offense"))
{
e.setCancelled(true);
this._player.closeInventory();
PunishGeneralOffense();
}

e.setCancelled(true);
}

/**
* Modified Client Punishment
*
* Temporary Ban.
*/
public void PunishModifiedClient()
{
Bukkit.dispatchCommand((CommandSender) _player, "sudo " + _player.getName() + " tempban "+ _target.getName() + " 86400");
this._player.playSound(this._player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
}

/**
* Chat Spam/Advertising
*
* 1 Hour Mute.
*/
public void PunishChatSpam()
{
Bukkit.dispatchCommand((CommandSender) _player, "mute " + _target.getName() + " 3600");
this._player.playSound(this._player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
}

/**
* Bug Exploitation/Glitch
*
* 3 Hours Ban.
*/
public void PunishBugExploit()
{
Bukkit.dispatchCommand((CommandSender) _player, "tempban " + _target.getName() + " 10800");
this._player.playSound(this._player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
}

/**
* General/Other offense
*
* 2 Hours Ban.
*/
public void PunishGeneralOffense()
{
Bukkit.dispatchCommand((CommandSender) _player, "tempban " + _target.getName() + " 7200");
this._player.playSound(this._player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
}

最佳答案

您可以为惩罚命令添加冷却时间,只允许玩家每秒运行一次惩罚。这应该会减少大部分垃圾邮件。查看 map 并保留玩家上次执行惩罚的历史记录。如果他们执行惩罚后还没有经过 X 秒,就不要让他们执行惩罚。

关于java - 如何仅点击一次库存项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25041119/

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