mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-03-12 13:29:46 +01:00
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:
parent
6e464107b4
commit
3d22067746
@ -176,6 +176,8 @@ ItemShortcut:
|
|||||||
ImproveDeathChestCompatibility: false
|
ImproveDeathChestCompatibility: false
|
||||||
# Prevents the backpack from being used as a hat
|
# Prevents the backpack from being used as a hat
|
||||||
BlockAsHat: false
|
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:
|
Sound:
|
||||||
# Enables all sound effects
|
# Enables all sound effects
|
||||||
@ -202,4 +204,4 @@ Misc:
|
|||||||
UseBungeeCord: false
|
UseBungeeCord: false
|
||||||
|
|
||||||
# Config file version. Don't touch it!
|
# Config file version. Don't touch it!
|
||||||
Version: 27
|
Version: 28
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
public class Config extends Configuration implements DatabaseConnectionConfiguration
|
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)
|
public Config(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
@ -394,6 +394,11 @@ public boolean isItemShortcutBlockAsHatEnabled()
|
|||||||
{
|
{
|
||||||
return getConfigE().getBoolean("ItemShortcut.BlockAsHat", false);
|
return getConfigE().getBoolean("ItemShortcut.BlockAsHat", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRightClickOnContainerAllowed()
|
||||||
|
{
|
||||||
|
return getConfigE().getBoolean("ItemShortcut.OpenContainerOnRightClick", false) && MCVersion.isNewerOrEqualThan(MCVersion.MC_1_13);
|
||||||
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Sound settings
|
//region Sound settings
|
||||||
|
@ -40,7 +40,9 @@
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ItemShortcut implements Listener
|
public class ItemShortcut implements Listener
|
||||||
@ -49,7 +51,8 @@ public class ItemShortcut implements Listener
|
|||||||
private final Minepacks plugin;
|
private final Minepacks plugin;
|
||||||
private final String itemName, value;
|
private final String itemName, value;
|
||||||
private final Message messageDoNotRemoveItem;
|
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)
|
public ItemShortcut(Minepacks plugin)
|
||||||
{
|
{
|
||||||
@ -58,7 +61,21 @@ public ItemShortcut(Minepacks plugin)
|
|||||||
value = plugin.getConfiguration().getItemShortcutHeadValue();
|
value = plugin.getConfiguration().getItemShortcutHeadValue();
|
||||||
improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled();
|
improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled();
|
||||||
blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled();
|
blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled();
|
||||||
|
allowRightClickOnContainers = plugin.getConfiguration().isRightClickOnContainerAllowed();
|
||||||
messageDoNotRemoveItem = plugin.getLanguage().getMessage("Ingame.DontRemoveShortcut");
|
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)
|
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 ((event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) return;
|
||||||
if(isItemShortcut(event.getItem()))
|
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.getPlayer().performCommand("backpack open");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.3.4-RC1</revision>
|
<revision>2.3.4-RC2</revision>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
Loading…
Reference in New Issue
Block a user