9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-29 20:09:13 +00:00

feat: add HMCColor support in commands, resolves #114

This commit is contained in:
LoJoSho
2023-11-20 17:05:23 -06:00
parent 617df48cc2
commit 3ee959abd6
3 changed files with 43 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
package com.hibiscusmc.hmccosmetics.command;
import com.hibiscusmc.hmccolor.HMCColorConfig;
import com.hibiscusmc.hmccolor.HMCColorContextKt;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
@@ -14,6 +16,7 @@ import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -104,7 +107,20 @@ public class CosmeticCommand implements CommandExecutor {
}
if (sender.hasPermission("hmccosmetics.cmd.apply.color")) {
if (args.length >= 4) color = ServerUtils.hex2Rgb(args[3]);
if (args.length >= 4) {
// TODO: Add sub-color support somehow... (and make this neater)
String textColor = args[3];
if (!textColor.contains("#") && Hooks.isActiveHook("HMCColor")) {
HMCColorConfig.Colors colors = HMCColorContextKt.getHmcColor().getConfig().getColors().get(textColor);
if (colors != null) {
String hmccolor = colors.getBaseColor().getColor();
if (hmccolor.contains("#")) color = ServerUtils.hex2Rgb(hmccolor);
else color = ServerUtils.rgbToRgb(hmccolor);
}
} else {
color = ServerUtils.hex2Rgb(textColor);
}
}
}
if (args.length == 1) {

View File

@@ -1,5 +1,8 @@
package com.hibiscusmc.hmccosmetics.command;
import com.hibiscusmc.hmccolor.HMCColorConfig;
import com.hibiscusmc.hmccolor.HMCColorContext;
import com.hibiscusmc.hmccolor.HMCColorContextKt;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
@@ -8,6 +11,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import org.bukkit.Bukkit;
@@ -122,6 +126,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
String subcommand = args[0].toLowerCase();
switch (subcommand) {
case "apply" -> {
if (Hooks.isActiveHook("HMCColor")) completions.addAll(HMCColorContextKt.getHmcColor().getConfig().getColors().keySet());
completions.add("#FFFFFF");
}
}

View File

@@ -36,6 +36,11 @@ public class ServerUtils {
return NMSHandlers.getHandler().getEntity(entityId);
}
/**
* This takes in a string like #FFFFFF to convert it into a Bukkit color
* @param colorStr
* @return
*/
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));
@@ -48,6 +53,22 @@ public class ServerUtils {
return Color.WHITE;
}
/**
* This takes in a string like 55,49,181 to convert it into a Bukkit Color
* @param colorStr
* @return
*/
public static Color rgbToRgb(String colorStr) {
if (colorStr.contains(",")) {
String[] colors = colorStr.split(",", 3);
if (colors.length == 3) {
return Color.fromRGB(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]));
}
}
return Color.WHITE;
}
// particle amount offsetxyz
// Ex. HEART 10 0.1 0.1 0.1
public static Particle addParticleValues(Particle particle, String[] split) {