From 124f8651048f72563784c57da30cb9aa6e6d5d74 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 9 Jan 2020 14:11:44 +0100 Subject: [PATCH] Prevent players from adding the shortcut to item frames and armor stands --- pom.xml | 2 +- .../Minepacks/Bukkit/Database/Config.java | 2 +- .../Bukkit/Listener/ItemShortcut.java | 39 +++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 448f47d..18fd6aa 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 at.pcgamingfreaks Minepacks - 2.1.1 + 2.1.2 scm:git:git@github.com:GeorgH93/Minepacks.git diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index d027ed5..562f5a7 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -113,7 +113,7 @@ public String getDBFields(String sub, String def) public boolean getUseUUIDs() { boolean uuid = getConfigE().getBoolean("Database.UseUUIDs", true); - if(!uuid) logger.warning(ConsoleColor.RED + "Disabling UUIDs is not recommended and can lead to unexpected behaviour. Please consider enabling UUIDs. The option will be removed with v2.1." + ConsoleColor.RESET); + if(!uuid) logger.warning(ConsoleColor.RED + "Disabling UUIDs is not recommended and can lead to unexpected behaviour. Please consider enabling UUIDs. The option will be removed at some point." + ConsoleColor.RESET); return uuid; } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index 50deeb4..909ff25 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -18,6 +18,7 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Listener; import at.pcgamingfreaks.Bukkit.HeadUtils; +import at.pcgamingfreaks.Bukkit.MCVersion; import at.pcgamingfreaks.Bukkit.Message.Message; import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; @@ -33,10 +34,8 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.*; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; @@ -97,6 +96,38 @@ public void onItemInteract(PlayerInteractEvent event) } } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onArmorStandManipulation(PlayerArmorStandManipulateEvent event) + { + if(isItemShortcut(event.getPlayerItem())) + { + event.getPlayer().performCommand("backpack open"); + event.setCancelled(true); + } + } + + private static final boolean DUAL_WIELDING_MC = MCVersion.isNewerOrEqualThan(MCVersion.MC_1_9); + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onItemFrameInteract(PlayerInteractEntityEvent event) + { + Player player = event.getPlayer(); + ItemStack item; + if(DUAL_WIELDING_MC) + { + item = (event.getHand() == EquipmentSlot.HAND) ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand(); + } + else + { + item = player.getItemInHand(); + } + if(isItemShortcut(item)) + { + event.getPlayer().performCommand("backpack open"); + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.LOWEST) public void onItemClick(InventoryClickEvent event) {