mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-10 12:50:17 +01:00
Annotation, fix cursor item not being cleared
This commit is contained in:
parent
8e9d7098e5
commit
7e3035709f
@ -59,7 +59,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
return option.fill(this, pair.left(), pair.right());
|
||||
}
|
||||
|
||||
public synchronized <T> @NotNull List<@NotNull T> processItemStacks(@NotNull List<ItemStack> itemStacks,
|
||||
public synchronized <T> @NotNull List<@NotNull T> processItemStacks(@NotNull List<@NotNull ItemStack> itemStacks,
|
||||
@NotNull TransactionType type,
|
||||
@NotNull TransactionOption<T> option) {
|
||||
List<T> result = new ArrayList<>(itemStacks.size());
|
||||
@ -92,7 +92,8 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
* @param option the transaction option
|
||||
* @return the operation results
|
||||
*/
|
||||
public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull TransactionOption<T> option) {
|
||||
public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull List<@NotNull ItemStack> itemStacks,
|
||||
@NotNull TransactionOption<T> option) {
|
||||
return processItemStacks(itemStacks, TransactionType.ADD, option);
|
||||
}
|
||||
|
||||
@ -112,7 +113,8 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
* @param itemStacks items to take
|
||||
* @return the operation results
|
||||
*/
|
||||
public <T> @NotNull List<@NotNull T> takeItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull TransactionOption<T> option) {
|
||||
public <T> @NotNull List<@NotNull T> takeItemStacks(@NotNull List<@NotNull ItemStack> itemStacks,
|
||||
@NotNull TransactionOption<T> option) {
|
||||
return processItemStacks(itemStacks, TransactionType.TAKE, option);
|
||||
}
|
||||
|
||||
@ -178,7 +180,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
*
|
||||
* @return a modifiable {@link List} containing all the inventory conditions
|
||||
*/
|
||||
public @NotNull List<InventoryCondition> getInventoryConditions() {
|
||||
public @NotNull List<@NotNull InventoryCondition> getInventoryConditions() {
|
||||
return inventoryConditions;
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,14 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void clear() {
|
||||
super.clear();
|
||||
// Clear cursor
|
||||
getViewers().forEach(player ->
|
||||
setCursorItem(player, ItemStack.AIR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the inventory for all viewers.
|
||||
*/
|
||||
@ -265,7 +273,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
* @param player the player to change the cursor item
|
||||
* @param itemStack the cursor item
|
||||
*/
|
||||
private void setCursorPlayerItem(@NotNull Player player, @NotNull ItemStack itemStack) {
|
||||
private void refreshPlayerCursorItem(@NotNull Player player, @NotNull ItemStack itemStack) {
|
||||
this.cursorPlayersItem.put(player, itemStack);
|
||||
}
|
||||
|
||||
@ -292,7 +300,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
} else {
|
||||
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
||||
}
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||
@ -319,7 +327,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
} else {
|
||||
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
||||
}
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
||||
@ -377,7 +385,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
updateFromClick(clickResult, player);
|
||||
}
|
||||
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
playerInventory.update();
|
||||
update();
|
||||
|
||||
@ -446,7 +454,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
}
|
||||
}
|
||||
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
|
||||
return !clickResult.isCancel();
|
||||
}
|
||||
@ -484,7 +492,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
updateFromClick(clickResult, player);
|
||||
}
|
||||
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
|
||||
return !clickResult.isCancel();
|
||||
}
|
||||
@ -513,7 +521,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
if (clickResult.doRefresh())
|
||||
updateFromClick(clickResult, player);
|
||||
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||
|
||||
return !clickResult.isCancel();
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
|
||||
@Override
|
||||
public synchronized void clear() {
|
||||
super.clear();
|
||||
// Reset cursor
|
||||
setCursorItem(ItemStack.AIR);
|
||||
// Update equipments
|
||||
this.player.sendPacketToViewersAndSelf(player.getEquipmentsPacket());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user