Add option to prevent the backpack from being used as a hat

This commit is contained in:
GeorgH93 2020-03-04 00:17:12 +01:00
parent 7fdc2acc45
commit 53d8183368
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
4 changed files with 23 additions and 11 deletions

View File

@ -174,6 +174,8 @@ ItemShortcut:
HeadTextureValue: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjYzZlYjQwZjNiYWRhNDFlNDMzOTg4OGQ2ZDIwNzQzNzU5OGJkYmQxNzVjMmU3MzExOTFkNWE5YTQyZDNjOCJ9fX0="
# Increases compatibility with some death chest plugins. Enable this if the backpack item is added to your death chest!
ImproveDeathChestCompatibility: false
# Prevents the backpack from being used as a hat
BlockAsHat: false
Sound:
# Enables all sound effects
@ -200,4 +202,4 @@ Misc:
UseBungeeCord: false
# Config file version. Don't touch it!
Version: 26
Version: 27

View File

@ -38,7 +38,7 @@
public class Config extends Configuration implements DatabaseConnectionConfiguration
{
private static final int CONFIG_VERSION = 26, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
private static final int CONFIG_VERSION = 27, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
public Config(JavaPlugin plugin)
{
@ -389,6 +389,11 @@ public boolean isItemShortcutImproveDeathChestCompatibilityEnabled()
{
return getConfigE().getBoolean("ItemShortcut.ImproveDeathChestCompatibility", false);
}
public boolean isItemShortcutBlockAsHatEnabled()
{
return getConfigE().getBoolean("ItemShortcut.BlockAsHat", false);
}
//endregion
//region Sound settings

View File

@ -34,10 +34,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -52,7 +49,7 @@ public class ItemShortcut implements Listener
private final Minepacks plugin;
private final String itemName, value;
private final Message messageDoNotRemoveItem;
private boolean improveDeathChestCompatibility;
private final boolean improveDeathChestCompatibility, blockAsHat;
public ItemShortcut(Minepacks plugin)
{
@ -60,6 +57,7 @@ public ItemShortcut(Minepacks plugin)
itemName = ChatColor.translateAlternateColorCodes('&', plugin.getConfiguration().getItemShortcutItemName());
value = plugin.getConfiguration().getItemShortcutHeadValue();
improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled();
blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled();
messageDoNotRemoveItem = plugin.getLanguage().getMessage("Ingame.DontRemoveShortcut");
}
@ -210,10 +208,17 @@ else if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.get
messageDoNotRemoveItem.send(player);
}
}
else if(isItemShortcut(event.getCursor()) && !player.getInventory().equals(event.getClickedInventory()))
else if(isItemShortcut(event.getCursor()))
{
event.setCancelled(true);
messageDoNotRemoveItem.send(player);
if(!player.getInventory().equals(event.getClickedInventory()))
{
event.setCancelled(true);
messageDoNotRemoveItem.send(player);
}
else if(event.getSlotType() == InventoryType.SlotType.ARMOR && blockAsHat)
{
event.setCancelled(true);
}
}
}
}

View File

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