mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-31 21:06:38 +00:00
Add new color handling (Thanks Boy!)
This commit is contained in:
@@ -248,7 +248,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
|
||||
if (args.length >= 3) {
|
||||
if (!args[2].contains("#") || args[2].isEmpty()) {
|
||||
if (args[2].isEmpty()) {
|
||||
MessagesUtil.sendMessage(player, "invalid-color");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.items.ItemHooks;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
@@ -126,7 +127,11 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
|
||||
if (!colorNode.virtual()) {
|
||||
if (ColorBuilder.canBeColored(item.getType())) {
|
||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
||||
if (!redNode.virtual()) {
|
||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
||||
} else {
|
||||
itemMeta = ColorBuilder.color(itemMeta, ServerUtils.hex2Rgb(colorNode.getString("#FFFFFF")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,16 @@ public class ServerUtils {
|
||||
}
|
||||
|
||||
public static Color hex2Rgb(String colorStr) {
|
||||
if (colorStr.startsWith("#")) return Color.fromRGB(Integer.valueOf(colorStr.substring(1), 16));
|
||||
if (colorStr.startsWith("0x")) return Color.fromRGB(Integer.valueOf(colorStr.substring(2), 16));
|
||||
if (colorStr.contains(",")) {
|
||||
String[] colorString = colorStr.replace(" ", "").split(",");
|
||||
for (String color : colorString) if (Integer.valueOf(color) == null) return Color.WHITE;
|
||||
Color.fromRGB(Integer.valueOf(colorString[0]), Integer.valueOf(colorString[1]), Integer.valueOf(colorString[2]));
|
||||
}
|
||||
|
||||
return Color.WHITE;
|
||||
/* Old method
|
||||
try {
|
||||
return Color.fromRGB(
|
||||
Integer.valueOf(colorStr.substring(1, 3), 16),
|
||||
@@ -45,6 +55,7 @@ public class ServerUtils {
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// particle amount offsetxyz
|
||||
|
||||
Reference in New Issue
Block a user