diff --git a/Minepacks/resources/config.yml b/Minepacks/resources/config.yml index 5687ce0..16b18c1 100644 --- a/Minepacks/resources/config.yml +++ b/Minepacks/resources/config.yml @@ -176,6 +176,8 @@ ItemShortcut: ImproveDeathChestCompatibility: false # Prevents the backpack from being used as a hat BlockAsHat: false + # Opens a container if right clicked while holding the backpack shortcut in the hand. This option will only work on MC 1.13 or newer. + OpenContainerOnRightClick: false Sound: # Enables all sound effects @@ -202,4 +204,4 @@ Misc: UseBungeeCord: false # Config file version. Don't touch it! -Version: 27 \ No newline at end of file +Version: 28 \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index 119d81c..8ede94d 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -38,7 +38,7 @@ public class Config extends Configuration implements DatabaseConnectionConfiguration { - private static final int CONFIG_VERSION = 27, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20; + private static final int CONFIG_VERSION = 28, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20; public Config(JavaPlugin plugin) { @@ -394,6 +394,11 @@ public boolean isItemShortcutBlockAsHatEnabled() { return getConfigE().getBoolean("ItemShortcut.BlockAsHat", false); } + + public boolean isRightClickOnContainerAllowed() + { + return getConfigE().getBoolean("ItemShortcut.OpenContainerOnRightClick", false) && MCVersion.isNewerOrEqualThan(MCVersion.MC_1_13); + } //endregion //region Sound settings diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index 5d2f3b4..b455a41 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -40,7 +40,9 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import java.util.UUID; public class ItemShortcut implements Listener @@ -49,7 +51,8 @@ public class ItemShortcut implements Listener private final Minepacks plugin; private final String itemName, value; private final Message messageDoNotRemoveItem; - private final boolean improveDeathChestCompatibility, blockAsHat; + private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers; + private final Set containerMaterials = new HashSet<>(); public ItemShortcut(Minepacks plugin) { @@ -58,7 +61,21 @@ public ItemShortcut(Minepacks plugin) value = plugin.getConfiguration().getItemShortcutHeadValue(); improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled(); blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled(); + allowRightClickOnContainers = plugin.getConfiguration().isRightClickOnContainerAllowed(); messageDoNotRemoveItem = plugin.getLanguage().getMessage("Ingame.DontRemoveShortcut"); + if(allowRightClickOnContainers) + { + containerMaterials.add(Material.CHEST); + containerMaterials.add(Material.TRAPPED_CHEST); + containerMaterials.add(Material.ENDER_CHEST); + containerMaterials.add(Material.CRAFTING_TABLE); + containerMaterials.add(Material.FURNACE); + containerMaterials.add(Material.BLAST_FURNACE); + containerMaterials.add(Material.DISPENSER); + containerMaterials.add(Material.DROPPER); + containerMaterials.add(Material.HOPPER); + if(MCVersion.isNewerOrEqualThan(MCVersion.MC_1_11)) containerMaterials.addAll(DisableShulkerboxes.SHULKER_BOX_MATERIALS); + } } private boolean isItemShortcut(@Nullable ItemStack stack) @@ -122,6 +139,11 @@ public void onItemInteract(PlayerInteractEvent event) if ((event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) return; if(isItemShortcut(event.getItem())) { + if(allowRightClickOnContainers && event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + //noinspection ConstantConditions + if(containerMaterials.contains(event.getClickedBlock().getType())) return; + } event.getPlayer().performCommand("backpack open"); event.setCancelled(true); } diff --git a/pom.xml b/pom.xml index caeebd9..38aa5f3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom - 2.3.4-RC1 + 2.3.4-RC2 UTF-8 UTF-8