mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 09:57:45 +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());
|
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 TransactionType type,
|
||||||
@NotNull TransactionOption<T> option) {
|
@NotNull TransactionOption<T> option) {
|
||||||
List<T> result = new ArrayList<>(itemStacks.size());
|
List<T> result = new ArrayList<>(itemStacks.size());
|
||||||
@ -92,7 +92,8 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
|||||||
* @param option the transaction option
|
* @param option the transaction option
|
||||||
* @return the operation results
|
* @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);
|
return processItemStacks(itemStacks, TransactionType.ADD, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,8 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
|||||||
* @param itemStacks items to take
|
* @param itemStacks items to take
|
||||||
* @return the operation results
|
* @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);
|
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
|
* @return a modifiable {@link List} containing all the inventory conditions
|
||||||
*/
|
*/
|
||||||
public @NotNull List<InventoryCondition> getInventoryConditions() {
|
public @NotNull List<@NotNull InventoryCondition> getInventoryConditions() {
|
||||||
return inventoryConditions;
|
return inventoryConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +121,14 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void clear() {
|
||||||
|
super.clear();
|
||||||
|
// Clear cursor
|
||||||
|
getViewers().forEach(player ->
|
||||||
|
setCursorItem(player, ItemStack.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes the inventory for all viewers.
|
* 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 player the player to change the cursor item
|
||||||
* @param itemStack 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);
|
this.cursorPlayersItem.put(player, itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +300,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
} else {
|
} else {
|
||||||
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
||||||
}
|
}
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
|
|
||||||
if (!clickResult.isCancel())
|
if (!clickResult.isCancel())
|
||||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
callClickEvent(player, isInWindow ? this : null, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||||
@ -319,7 +327,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
} else {
|
} else {
|
||||||
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
playerInventory.setItemStack(clickSlot, clickResult.getClicked());
|
||||||
}
|
}
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
|
|
||||||
if (!clickResult.isCancel())
|
if (!clickResult.isCancel())
|
||||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
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);
|
updateFromClick(clickResult, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
playerInventory.update();
|
playerInventory.update();
|
||||||
update();
|
update();
|
||||||
|
|
||||||
@ -446,7 +454,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
|
|
||||||
return !clickResult.isCancel();
|
return !clickResult.isCancel();
|
||||||
}
|
}
|
||||||
@ -484,7 +492,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
updateFromClick(clickResult, player);
|
updateFromClick(clickResult, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
|
|
||||||
return !clickResult.isCancel();
|
return !clickResult.isCancel();
|
||||||
}
|
}
|
||||||
@ -513,7 +521,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
|||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
updateFromClick(clickResult, player);
|
updateFromClick(clickResult, player);
|
||||||
|
|
||||||
setCursorPlayerItem(player, clickResult.getCursor());
|
refreshPlayerCursorItem(player, clickResult.getCursor());
|
||||||
|
|
||||||
return !clickResult.isCancel();
|
return !clickResult.isCancel();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void clear() {
|
public synchronized void clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
|
// Reset cursor
|
||||||
|
setCursorItem(ItemStack.AIR);
|
||||||
// Update equipments
|
// Update equipments
|
||||||
this.player.sendPacketToViewersAndSelf(player.getEquipmentsPacket());
|
this.player.sendPacketToViewersAndSelf(player.getEquipmentsPacket());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user