9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-29 11:59:21 +00:00

Added dyeing menu

This commit is contained in:
HeroBrineGoat
2021-11-11 19:08:53 -05:00
parent b2550b20a7
commit 607b07aecb
17 changed files with 443 additions and 161 deletions

View File

@@ -0,0 +1,88 @@
package io.github.fisher2911.hmccosmetics.util.builder;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import java.util.EnumSet;
import java.util.Set;
public class ColorBuilder extends ItemBuilder{
/**
*
* @param material ItemStack material
*/
ColorBuilder(final Material material) {
super(material);
}
/**
*
* @param itemStack ItemStack
*/
ColorBuilder(final ItemStack itemStack) {
super(itemStack);
}
/**
*
* @param material ItemStack material
* @return this
* @throws IllegalArgumentException thrown if itemStack's type can not change color
*/
public static ColorBuilder from(final Material material) throws IllegalArgumentException {
if (!canBeColored(material)) {
throw new IllegalArgumentException(material.name() + " is not leather armor!");
}
return new ColorBuilder(material);
}
/**
*
* @param itemStack ItemStack
* @return this
* @throws IllegalArgumentException thrown if itemStack's type can not change color
*/
public static ColorBuilder from(final ItemStack itemStack) throws IllegalArgumentException {
final Material material = itemStack.getType();
if (!canBeColored(itemStack)) {
throw new IllegalArgumentException(material.name() + " is not leather armor!");
}
return new ColorBuilder(itemStack);
}
/**
*
* @param color armor color
* @return this
*/
public ColorBuilder color(final Color color) {
if (this.itemMeta instanceof final PotionMeta meta) {
meta.setColor(color);
}
if (this.itemMeta instanceof final LeatherArmorMeta meta) {
meta.setColor(color);
}
return this;
}
public static boolean canBeColored(final Material material) {
return canBeColored(new ItemStack(material));
}
public static boolean canBeColored(final ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
return (itemMeta instanceof LeatherArmorMeta ||
itemMeta instanceof PotionMeta);
}
}

View File

@@ -2,6 +2,7 @@ package io.github.fisher2911.hmccosmetics.util.builder;
import io.github.fisher2911.hmccosmetics.message.Adventure;
import io.github.fisher2911.hmccosmetics.util.StringUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@@ -76,6 +77,11 @@ public class ItemBuilder {
return this;
}
public ItemBuilder name(final Component name) {
this.itemMeta.displayName(name);
return this;
}
/**
* Sets placeholders to the item's name
*

View File

@@ -1,86 +0,0 @@
package io.github.fisher2911.hmccosmetics.util.builder;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import java.util.EnumSet;
import java.util.Set;
public class LeatherArmorBuilder extends ItemBuilder{
private static final Set<Material> VALID_ARMOR = EnumSet.of(Material.LEATHER_BOOTS,
Material.LEATHER_LEGGINGS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET);
/**
*
* @param material ItemStack material
*/
LeatherArmorBuilder(final Material material) {
super(material);
}
/**
*
* @param itemStack ItemStack
*/
LeatherArmorBuilder(final ItemStack itemStack) {
super(itemStack);
}
/**
*
* @param material ItemStack material
* @return this
* @throws IllegalArgumentException thrown if material is not leather armor
*/
public static LeatherArmorBuilder from(final Material material) throws IllegalArgumentException {
if (!VALID_ARMOR.contains(material)) {
throw new IllegalArgumentException(material.name() + " is not leather armor!");
}
return new LeatherArmorBuilder(material);
}
/**
*
* @param itemStack ItemStack
* @return this
* @throws IllegalArgumentException thrown if itemStack's type is not leather armor
*/
public static LeatherArmorBuilder from(final ItemStack itemStack) throws IllegalArgumentException {
final Material material = itemStack.getType();
if (!VALID_ARMOR.contains(material)) {
throw new IllegalArgumentException(material.name() + " is not leather armor!");
}
return new LeatherArmorBuilder(itemStack);
}
/**
*
* @param color armor color
* @return this
*/
public LeatherArmorBuilder color(final Color color) {
if (itemMeta instanceof final LeatherArmorMeta meta) {
meta.setColor(color);
this.itemMeta = meta;
}
return this;
}
/**
*
* @param material checked material
* @return true if is leather armor, else false
*/
public static boolean isLeatherArmor(final Material material) {
return VALID_ARMOR.contains(material);
}
}