mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-21 01:01:35 +08:00
Fix /clear <player> <item> not clearing offhand (#3715)
Co-authored-by: Kenichycmd <kenichycmd@gmail.com> Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
This commit is contained in:
parent
5b0c2a4131
commit
80fb91b6d7
@ -137,7 +137,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
if (amount == -1) {
|
||||
stack.setAmount(BASE_AMOUNT);
|
||||
final ItemStack removedStack = player.getInventory().removeItem(stack).get(0);
|
||||
final int removedAmount = BASE_AMOUNT - removedStack.getAmount();
|
||||
final int removedAmount = BASE_AMOUNT - removedStack.getAmount() + InventoryWorkaround.clearItemInOffHand(player, stack);
|
||||
if (removedAmount > 0 || showExtended) {
|
||||
sender.sendMessage(tl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()));
|
||||
}
|
||||
|
@ -267,4 +267,22 @@ public final class InventoryWorkaround {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int clearItemInOffHand(final Player p, final ItemStack item) {
|
||||
// This should be added because if `/clear` itself is not initilized it will return an Error: null.
|
||||
if (hasMainHandSupport == null || hasMainHandSupport) {
|
||||
try {
|
||||
int removedAmount = 0;
|
||||
if (p.getInventory().getItemInOffHand().getType().equals(item.getType())) {
|
||||
removedAmount = p.getInventory().getItemInOffHand().getAmount();
|
||||
p.getInventory().setItemInOffHand(null);
|
||||
}
|
||||
hasMainHandSupport = true;
|
||||
return removedAmount;
|
||||
} catch (final Throwable e) {
|
||||
hasMainHandSupport = false;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user