Java 禁止移动,在 Minecraft 的 GUI 中添加项目
Forbidding the ability to move, add items in a GUI on Minecraft in Java
信息:
插口:1.12 & Java 版本:8
我尝试让玩家在 GUI 时,一旦 GUI 关闭,他就可以拿走物品,因为:https://gyazo.com/27ccc89e0b5c8f0780bcdca906eab5af
所以我创建了一个新的 class 来与事件 (InventoryClickEvent) 交互,问题是当它应用时它从头到尾应用,除了我想把它放在一个条件下:如果玩家打开GUI 他不能拿走这个 GUI 中的物品,如果他关闭它,该事件将无效,玩家将能够拿走 gamemode/or 中的物品 从他的库存中移动物品(例如)
我的问题是我不知道如何在我创建的循环中应用它(对于我的 GUI)
我使用 CommandExecutor / 不允许我使用事件(我认为)
我的代码:
命令:https://bin.readthedocs.fr/jeedur.txt
点击事件:https://bin.readthedocs.fr/nermit.txt
使用静态列表(作为字段)存储所有打开了 GUI 的玩家。当玩家执行命令时,您将他们添加到列表中。当他关闭库存 (InventoryCloseEvent) 时,您将移除玩家。然后在 InventoryClickEvent 中检查播放器是否在列表中。如果是这样,您将阻止该事件。
代码部分:
将其置于您的命令之上 class(从 java.util 导入 List 和 ArrayList。*)[命令行 20]:
public static List<Player> playersInInventory = new ArrayList<>();
就在您打开清单之前[命令行 142]:
Commands.playersInInventory.add(player);
在您的 InventoryCloseEvent 中[创建此事件]:
Commands.playersInInventory.remove(event.getPlayer());
然后你可以在你的InventoryClickEvent中使用这个[你的事件的唯一内容]:
if (Commands.playersInInventory.contains((Player) (event.getWhoClicked()))) {
event.setCancelled(true);
}
这段代码应该可以正常工作,但我还没有测试过。如果它不起作用,请告诉我。
信息: 插口:1.12 & Java 版本:8
我尝试让玩家在 GUI 时,一旦 GUI 关闭,他就可以拿走物品,因为:https://gyazo.com/27ccc89e0b5c8f0780bcdca906eab5af 所以我创建了一个新的 class 来与事件 (InventoryClickEvent) 交互,问题是当它应用时它从头到尾应用,除了我想把它放在一个条件下:如果玩家打开GUI 他不能拿走这个 GUI 中的物品,如果他关闭它,该事件将无效,玩家将能够拿走 gamemode/or 中的物品 从他的库存中移动物品(例如)
我的问题是我不知道如何在我创建的循环中应用它(对于我的 GUI) 我使用 CommandExecutor / 不允许我使用事件(我认为)
我的代码: 命令:https://bin.readthedocs.fr/jeedur.txt 点击事件:https://bin.readthedocs.fr/nermit.txt
使用静态列表(作为字段)存储所有打开了 GUI 的玩家。当玩家执行命令时,您将他们添加到列表中。当他关闭库存 (InventoryCloseEvent) 时,您将移除玩家。然后在 InventoryClickEvent 中检查播放器是否在列表中。如果是这样,您将阻止该事件。
代码部分:
将其置于您的命令之上 class(从 java.util 导入 List 和 ArrayList。*)[命令行 20]:
public static List<Player> playersInInventory = new ArrayList<>();
就在您打开清单之前[命令行 142]:
Commands.playersInInventory.add(player);
在您的 InventoryCloseEvent 中[创建此事件]:
Commands.playersInInventory.remove(event.getPlayer());
然后你可以在你的InventoryClickEvent中使用这个[你的事件的唯一内容]:
if (Commands.playersInInventory.contains((Player) (event.getWhoClicked()))) {
event.setCancelled(true);
}
这段代码应该可以正常工作,但我还没有测试过。如果它不起作用,请告诉我。