-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
9 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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/artillexstudios/axgraves/utils/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,53 @@ | ||
package com.artillexstudios.axgraves.utils; | ||
|
||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.PlayerInventory; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import static com.artillexstudios.axgraves.AxGraves.CONFIG; | ||
|
||
public class InventoryUtils { | ||
|
||
@NotNull | ||
public static ItemStack[] reOrderInventory(@NotNull PlayerInventory inventory, @NotNull ItemStack[] keptItems) { | ||
final ArrayList<ItemStack> itemsBefore = new ArrayList<>(Arrays.asList(keptItems)); | ||
final ItemStack[] items = new ItemStack[itemsBefore.size()]; | ||
int n = 0; | ||
|
||
for (String str : CONFIG.getStringList("grave-item-order")) { | ||
switch (str) { | ||
case "ARMOR" -> { | ||
for (ItemStack it : inventory.getArmorContents()) { | ||
if (!itemsBefore.contains(it)) continue; | ||
items[n] = it; | ||
itemsBefore.remove(it); | ||
n++; | ||
} | ||
} | ||
case "HAND" -> { | ||
if (!itemsBefore.contains(inventory.getItemInMainHand())) continue; | ||
items[n] = inventory.getItemInMainHand(); | ||
itemsBefore.remove(inventory.getItemInMainHand()); | ||
n++; | ||
} | ||
case "OFFHAND" -> { | ||
if (!itemsBefore.contains(inventory.getItemInOffHand())) continue; | ||
items[n] = inventory.getItemInOffHand(); | ||
itemsBefore.remove(inventory.getItemInOffHand()); | ||
n++; | ||
} | ||
} | ||
} | ||
|
||
for (ItemStack it : itemsBefore) { | ||
if (!itemsBefore.contains(it)) continue; | ||
items[n] = it; | ||
n++; | ||
} | ||
|
||
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