Add option to select a preferred slot id for backpack item

This commit is contained in:
GeorgH93 2020-03-11 19:31:27 +01:00
parent 3d22067746
commit edf2c01785
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
4 changed files with 26 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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