mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
Added custom dye color command and message
This commit is contained in:
@@ -9,6 +9,7 @@ import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
@@ -16,6 +17,7 @@ import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -61,7 +63,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("dye")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DYE_COMMAND)
|
||||
public void dyeArmor(final Player player, @Completion("#types") String typeString) {
|
||||
public void dyeArmor(final Player player, @Completion("#types") String typeString, final @me.mattstudios.mf.annotations.Optional String dyeColor) {
|
||||
|
||||
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
|
||||
|
||||
@@ -74,7 +76,26 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
final User user = optionalUser.get();
|
||||
|
||||
this.cosmeticsMenu.openDyeSelectorGui(user, type);
|
||||
if (dyeColor == null) {
|
||||
this.cosmeticsMenu.openDyeSelectorGui(user, type);
|
||||
return;
|
||||
}
|
||||
|
||||
final java.awt.Color awtColor = java.awt.Color.decode(dyeColor);
|
||||
Color color = Color.fromRGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
|
||||
|
||||
final ArmorItem armorItem = user.getPlayerArmor().getItem(type);
|
||||
|
||||
armorItem.setDye(color.asRGB());
|
||||
|
||||
this.userManager.setItem(user, armorItem);
|
||||
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.SET_DYE_COLOR,
|
||||
Map.of(Placeholder.ITEM, StringUtils.formatArmorItemType(typeString))
|
||||
);
|
||||
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
|
||||
@@ -21,6 +21,8 @@ public class Messages {
|
||||
new Message("set-off-hand", "Set off hand");
|
||||
public static final Message REMOVED_OFF_HAND =
|
||||
new Message("removed-off-hand", "Removed off hand");
|
||||
public static final Message SET_DYE_COLOR =
|
||||
new Message("set-dye-color", "Set dye color of " + Placeholder.ITEM);
|
||||
public static final Message MUST_BE_PLAYER =
|
||||
new Message("must-be-player", "You must be a player to do this!");
|
||||
public static final Message RELOADED =
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class StringUtils {
|
||||
@@ -51,4 +52,17 @@ public class StringUtils {
|
||||
public static String parseStringToString(final String parsed) {
|
||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.parse(parsed));
|
||||
}
|
||||
|
||||
public static String formatArmorItemType(String type) {
|
||||
type = type.toLowerCase();
|
||||
final String[] parts = type.split(" ");
|
||||
|
||||
final String firstPart = parts[0].substring(0, 1).toUpperCase() + parts[0].substring(1);
|
||||
|
||||
if (parts.length == 1) {
|
||||
return firstPart;
|
||||
}
|
||||
|
||||
return firstPart + parts[1].substring(0, 1).toUpperCase() + parts[1].substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user