Add option to allow containers to be opened instead of the backpack when right clicking them with the shortcut item #74

This commit is contained in:
GeorgH93 2020-03-11 15:58:09 +01:00
parent 6e464107b4
commit 3d22067746
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
4 changed files with 33 additions and 4 deletions

View File

@ -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
Version: 28

View File

@ -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

View File

@ -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<Material> 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);
}

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.3.4-RC1</revision>
<revision>2.3.4-RC2</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>