-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(trigger): drop items when inventory is full
Signed-off-by: SettingDust <[email protected]>
- Loading branch information
1 parent
00c01ba
commit cf6eb2d
Showing
9 changed files
with
106 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/team/ebi/epicbanitem/util/InventoryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 EpicBanItem Team. All Rights Reserved. | ||
* | ||
* This file is part of EpicBanItem, licensed under the GNU GENERAL PUBLIC LICENSE Version 3 (GPL-3.0) | ||
*/ | ||
package team.ebi.epicbanitem.util; | ||
|
||
import java.util.List; | ||
|
||
import org.spongepowered.api.entity.Item; | ||
import org.spongepowered.api.item.inventory.Inventory; | ||
import org.spongepowered.api.item.inventory.ItemStack; | ||
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; | ||
import org.spongepowered.api.world.server.ServerLocation; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
public final class InventoryUtils { | ||
public static List<Item> offerOrDrop(Inventory inventory, ServerLocation location, ItemStack... item) { | ||
final var result = inventory.offer(item); | ||
List<Item> items = Lists.newArrayList(); | ||
if (!result.type().equals(InventoryTransactionResult.Type.SUCCESS)) | ||
items = result.rejectedItems().stream() | ||
.map(it -> ItemUtils.droppedItem(it, location)) | ||
.toList(); | ||
return items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters