From ce1a5fca450f884c8b4c770b3f878f18f3784bc1 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Sun, 24 Oct 2021 11:28:22 +0200 Subject: [PATCH] Remove shortcut item in worlds where the player doesn't have the permission to use it (#184) --- .../Bukkit/Listener/ItemShortcut.java | 23 +++++++++++++++++-- pom.xml | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index 32bd3cf..9ed5ef1 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -123,6 +123,18 @@ else if(isItemShortcut(itemStack)) } } + private void removeItem(Player player) + { + for(ItemStack itemStack : player.getInventory()) + { + if(isItemShortcut(itemStack)) + { + itemStack.setAmount(0); + return; + } + } + } + //region Add backpack item @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onJoin(PlayerJoinEvent event) @@ -139,10 +151,17 @@ public void onSpawn(PlayerRespawnEvent event) } @EventHandler(priority = EventPriority.MONITOR) - public void onWorldChange(PlayerChangedWorldEvent event) + public void onWorldChange(final PlayerChangedWorldEvent event) { if(plugin.isDisabled(event.getPlayer()) != WorldBlacklistMode.None) return; - Bukkit.getScheduler().runTaskLater(plugin, () -> addItem(event.getPlayer()), 2L); + Bukkit.getScheduler().runTaskLater(plugin, () -> { + Player player = event.getPlayer(); + if(!player.isOnline()) return; + if(player.hasPermission(Permissions.USE)) + addItem(player); + else + removeItem(player); + }, 2L); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/pom.xml b/pom.xml index be98df6..29d82c7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom - 2.4.2 + 2.4.3-RC1 UTF-8 UTF-8