-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ItemMaterialFiller (Only obtainable item Material is found in this f…
…iller).
- Loading branch information
1 parent
4b2ed2d
commit 05839ee
Showing
3 changed files
with
77 additions
and
4 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
54 changes: 54 additions & 0 deletions
54
src/main/java/us/mytheria/bloblib/managers/fillermanager/ItemMaterialFiller.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,54 @@ | ||
package us.mytheria.bloblib.managers.fillermanager; | ||
|
||
import net.md_5.bungee.api.ChatColor; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import us.mytheria.bloblib.entities.VariableFiller; | ||
import us.mytheria.bloblib.entities.VariableValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ItemMaterialFiller implements VariableFiller<Material> { | ||
private final ArrayList<Material> materials; | ||
|
||
public ItemMaterialFiller() { | ||
materials = new ArrayList<>(); | ||
for (Material material : Material.values()) { | ||
if (material.name().contains("LEGACY")) | ||
continue; | ||
if (!material.isItem()) | ||
continue; | ||
if (new ItemStack(material).getItemMeta() == null) | ||
continue; | ||
materials.add(material); | ||
} | ||
} | ||
|
||
@Override | ||
public List<VariableValue<Material>> page(int page, int itemsPerPage) { | ||
int start = (page - 1) * itemsPerPage; | ||
int end = start + (itemsPerPage); | ||
ArrayList<VariableValue<Material>> values = new ArrayList<>(); | ||
for (int i = start; i < end; i++) { | ||
Material material; | ||
try { | ||
material = materials.get(i); | ||
ItemStack itemStack = new ItemStack(material); | ||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
itemMeta.setDisplayName(ChatColor.GOLD + material.name()); | ||
itemStack.setItemMeta(itemMeta); | ||
values.add(new VariableValue<>(itemStack, material)); | ||
} catch (IndexOutOfBoundsException e) { | ||
break; | ||
} | ||
} | ||
return values; | ||
} | ||
|
||
@Override | ||
public int totalPages(int itemsPerPage) { | ||
return (int) Math.ceil((double) materials.size() / (double) itemsPerPage); | ||
} | ||
} |