mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-14 10:45:23 +01:00
Add option to select a preferred slot id for backpack item
This commit is contained in:
parent
3d22067746
commit
edf2c01785
@ -178,6 +178,8 @@ ItemShortcut:
|
||||
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
|
||||
# The id of the slot that should be preferred when giving a player the shortcut item
|
||||
PreferredSlotId: -1
|
||||
|
||||
Sound:
|
||||
# Enables all sound effects
|
||||
|
@ -395,10 +395,15 @@ public boolean isItemShortcutBlockAsHatEnabled()
|
||||
return getConfigE().getBoolean("ItemShortcut.BlockAsHat", false);
|
||||
}
|
||||
|
||||
public boolean isRightClickOnContainerAllowed()
|
||||
public boolean isItemShortcutRightClickOnContainerAllowed()
|
||||
{
|
||||
return getConfigE().getBoolean("ItemShortcut.OpenContainerOnRightClick", false) && MCVersion.isNewerOrEqualThan(MCVersion.MC_1_13);
|
||||
}
|
||||
|
||||
public int getItemShortcutPreferredSlotId()
|
||||
{
|
||||
return getConfigE().getInt("ItemShortcut.PreferredSlotId", -1);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Sound settings
|
||||
|
@ -52,6 +52,7 @@ public class ItemShortcut implements Listener
|
||||
private final String itemName, value;
|
||||
private final Message messageDoNotRemoveItem;
|
||||
private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers;
|
||||
private final int preferredSlotId;
|
||||
private final Set<Material> containerMaterials = new HashSet<>();
|
||||
|
||||
public ItemShortcut(Minepacks plugin)
|
||||
@ -61,8 +62,10 @@ public ItemShortcut(Minepacks plugin)
|
||||
value = plugin.getConfiguration().getItemShortcutHeadValue();
|
||||
improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled();
|
||||
blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled();
|
||||
allowRightClickOnContainers = plugin.getConfiguration().isRightClickOnContainerAllowed();
|
||||
allowRightClickOnContainers = plugin.getConfiguration().isItemShortcutRightClickOnContainerAllowed();
|
||||
preferredSlotId = plugin.getConfiguration().getItemShortcutPreferredSlotId();
|
||||
messageDoNotRemoveItem = plugin.getLanguage().getMessage("Ingame.DontRemoveShortcut");
|
||||
|
||||
if(allowRightClickOnContainers)
|
||||
{
|
||||
containerMaterials.add(Material.CHEST);
|
||||
@ -98,7 +101,19 @@ else if(isItemShortcut(itemStack))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!item && empty) player.getInventory().addItem(HeadUtils.fromBase64(value, itemName, MINEPACKS_UUID));
|
||||
if(!item && empty)
|
||||
{
|
||||
if(preferredSlotId >= 0 && preferredSlotId < 36)
|
||||
{
|
||||
ItemStack stack = player.getInventory().getItem(preferredSlotId);
|
||||
if(stack == null || stack.getType() == Material.AIR)
|
||||
{
|
||||
player.getInventory().setItem(preferredSlotId, HeadUtils.fromBase64(value, itemName, MINEPACKS_UUID));
|
||||
return;
|
||||
}
|
||||
}
|
||||
player.getInventory().addItem(HeadUtils.fromBase64(value, itemName, MINEPACKS_UUID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user