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:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user