#1 Fixes being able to use abilities of items even when they are two-handed and you are carrying two in each hand.

If you wanted them to work this way, feel free to add to your config:
```yml
# Abilities can be used even when
# the player is encumbered by the
# items that give them
abilities-bypass-encumbering: true
```

Also added `RefreshInventoryEvent` that allows API check of which items are getting equipped, and thus allows to modify them somewhat.
This commit is contained in:
Gunging 2021-04-26 00:57:16 -05:00
parent 402fcfe26c
commit b13c285d85
3 changed files with 42 additions and 2 deletions

View File

@ -216,6 +216,9 @@ public class PlayerData {
inventory.getEquipped().add(new EquippedPlayerItem(item));
}
RefreshInventoryEvent riev = new RefreshInventoryEvent(inventory.getEquipped(), getPlayer(), this);
Bukkit.getPluginManager().callEvent(riev);
for (EquippedPlayerItem equipped : inventory.getEquipped()) {
VolatileMMOItem item = equipped.getItem();
@ -244,7 +247,7 @@ public class PlayerData {
/*
* Apply abilities
*/
if (item.hasData(ItemStats.ABILITIES))
if (item.hasData(ItemStats.ABILITIES) && (MMOItems.plugin.getConfig().getBoolean("abilities-bypass-encumbering", false) || !fullHands))
if (equipped.getSlot() != EquipmentSlot.OFF_HAND || !MMOItems.plugin.getConfig().getBoolean("disable-abilities-in-offhand"))
itemAbilities.addAll(((AbilityListData) item.getData(ItemStats.ABILITIES)).getAbilities());

View File

@ -0,0 +1,38 @@
package net.Indyuce.mmoitems.api.player;
import net.Indyuce.mmoitems.api.player.inventory.EquippedPlayerItem;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class RefreshInventoryEvent extends Event {
@NotNull final List<EquippedPlayerItem> itemsToEquip;
@NotNull public List<EquippedPlayerItem> getItemsToEquip() { return itemsToEquip; }
@NotNull
public Player getPlayer() {
return player;
}
@NotNull
public PlayerData getPlayerData() {
return playerData;
}
@NotNull final Player player;
@NotNull final PlayerData playerData;
public RefreshInventoryEvent(@NotNull List<EquippedPlayerItem> itemsToEquip, @NotNull Player player, @NotNull PlayerData playerData) {
this.itemsToEquip = itemsToEquip;
this.player = player;
this.playerData = playerData;
}
@NotNull static final HandlerList handlers = new HandlerList();
@NotNull public HandlerList getHandlers() { return handlers; }
@NotNull public static HandlerList getHandlerList() { return handlers; }
}

View File

@ -12,7 +12,6 @@ public class EquippedPlayerItem {
* An item equipped by a player in a specific slot
*
* @param item The item equipped
* @param slot The corresponding MMOItems slot type, must not be null!
*/
public EquippedPlayerItem(EquippedItem item) {
this.item = new VolatileMMOItem(item.getItem());