diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java index 940986da..5f7bfc88 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java @@ -10,8 +10,10 @@ 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 java.util.Map; import java.util.Optional; + import me.mattstudios.mf.annotations.Command; import me.mattstudios.mf.annotations.Completion; import me.mattstudios.mf.annotations.Default; @@ -62,7 +64,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, - final @me.mattstudios.mf.annotations.Optional String dyeColor) { + final @me.mattstudios.mf.annotations.Optional String dyeColor) { final Optional optionalUser = this.userManager.get(player.getUniqueId()); @@ -80,12 +82,9 @@ public class CosmeticsCommand extends CommandBase { 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.setDyeColor(dyeColor, armorItem, player); this.userManager.setItem(user, armorItem); @@ -113,8 +112,11 @@ public class CosmeticsCommand extends CommandBase { @SubCommand("add") @Permission(io.github.fisher2911.hmccosmetics.message.Permission.SET_COSMETIC_COMMAND) - public void setCommand(final CommandSender sender, @Completion("#players") final Player player, - @Completion("#ids") final String id) { + public void setCommand( + final CommandSender sender, + @Completion("#players") final Player player, + @Completion("#ids") final String id, + final @me.mattstudios.mf.annotations.Optional String dyeColor) { final Optional userOptional = this.userManager.get(player.getUniqueId()); if (userOptional.isEmpty()) { @@ -126,7 +128,6 @@ public class CosmeticsCommand extends CommandBase { } final User user = userOptional.get(); - final ArmorItem armorItem = this.plugin.getCosmeticManager().getArmorItem(id); if (armorItem == null) { @@ -137,6 +138,8 @@ public class CosmeticsCommand extends CommandBase { return; } + this.setDyeColor(dyeColor, armorItem, player); + final Message setMessage = Messages.getSetMessage(armorItem.getType()); final Message setOtherMessage = Messages.getSetOtherMessage(armorItem.getType()); this.userManager.setItem(user, armorItem); @@ -155,7 +158,7 @@ public class CosmeticsCommand extends CommandBase { @SubCommand("remove") @Permission(io.github.fisher2911.hmccosmetics.message.Permission.SET_COSMETIC_COMMAND) public void removeCommand(final CommandSender sender, - @Completion("#players") final Player player, @Completion("#types") String typeString) { + @Completion("#players") final Player player, @Completion("#types") String typeString) { final Optional userOptional = this.userManager.get(player.getUniqueId()); if (userOptional.isEmpty()) { @@ -184,4 +187,17 @@ public class CosmeticsCommand extends CommandBase { } } + private void setDyeColor(final String dyeColor, final ArmorItem armorItem, final CommandSender sender) { + try { + final java.awt.Color awtColor = java.awt.Color.decode(dyeColor); + Color color = Color.fromRGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue()); + armorItem.setDye(color.asRGB()); + } catch (final NumberFormatException exception) { + this.messageHandler.sendMessage( + sender, + Messages.INVALID_COLOR, + Map.of(Placeholder.ITEM, dyeColor) + ); + } + } } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java b/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java index a5a67c60..a03aaa3f 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java @@ -5,6 +5,8 @@ import org.bukkit.ChatColor; public class Messages { + public static final Message INVALID_COLOR = new Message( + "","" + Placeholder.ITEM + " is an invalid color."); public static final Message NO_PERMISSION = new Message("no-permission", "You do not have permission for this!"); public static final Message NO_COSMETIC_PERMISSION =