mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
fix armor trims
This commit is contained in:
parent
302bb96a3b
commit
2759e21250
@ -13,9 +13,6 @@ import org.bukkit.inventory.meta.trim.ArmorTrim;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TrimComponent implements ItemComponent {
|
||||
|
||||
@Override
|
||||
@ -23,38 +20,22 @@ public class TrimComponent implements ItemComponent {
|
||||
if (item.armorTrim() == null) return itemStack;
|
||||
|
||||
// trim: <Material> <Pattern>
|
||||
String[] trimList = ctx.text.parseTextToString(player, item.armorTrim())
|
||||
.split("\\s");
|
||||
String[] trimList = ctx.text.parseTextToString(player, item.armorTrim()).split("\\s+");
|
||||
if (trimList.length != 2) return itemStack;
|
||||
|
||||
String trimMaterialString = trimList[0].toLowerCase();
|
||||
String trimPatternString = trimList[1].toLowerCase();
|
||||
|
||||
// Check if Material and Pattern are valid and the item stack is an armor piece
|
||||
if (isTrimMaterial(trimMaterialString) && isTrimPattern(trimPatternString)) {
|
||||
|
||||
// Getting the correct Pattern and Material
|
||||
// Material and Pattern don't have a valueOf-function to get them the easier way.
|
||||
TrimMaterial trimMaterial = Registry.TRIM_MATERIAL.get(NamespacedKey.fromString("minecraft:" + trimMaterialString));
|
||||
TrimPattern trimPattern = Registry.TRIM_PATTERN.get(NamespacedKey.fromString("minecraft:" + trimPatternString));
|
||||
// Use registry lookups directly
|
||||
TrimMaterial trimMaterial = Registry.TRIM_MATERIAL.get(NamespacedKey.fromString("minecraft:" + trimMaterialString));
|
||||
TrimPattern trimPattern = Registry.TRIM_PATTERN.get(NamespacedKey.fromString("minecraft:" + trimPatternString));
|
||||
|
||||
// Only apply if both exist
|
||||
if (trimMaterial != null && trimPattern != null) {
|
||||
ArmorTrim trim = new ArmorTrim(trimMaterial, trimPattern);
|
||||
itemStack.setData(DataComponentTypes.TRIM,
|
||||
ItemArmorTrim.itemArmorTrim(trim));
|
||||
itemStack.setData(DataComponentTypes.TRIM, ItemArmorTrim.itemArmorTrim(trim));
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private boolean isTrimMaterial(String material) {
|
||||
List<String> availableMaterial = Arrays.asList("AMETHYST",
|
||||
"COPPER", "DIAMOND", "EMERALD", "GOLD", "IRON", "LAPIS", "NETHERITE", "QUARTZ", "REDSTONE");
|
||||
return availableMaterial.contains(material.toUpperCase());
|
||||
}
|
||||
|
||||
private boolean isTrimPattern(String pattern) {
|
||||
List<String> availablePattern = Arrays.asList("COAST",
|
||||
"DUNE", "EYE", "HOST", "RAISER", "RIB", "SENTRY", "SHAPER", "SILENCE", "SNOUT", "SPIRE", "TIDE", "VEX", "WARD", "WAYFINDER", "WILD");
|
||||
return availablePattern.contains(pattern.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user