Skip to content

Commit

Permalink
Refactor skin layer toggling logic in CharacterSkinCommand
Browse files Browse the repository at this point in the history
Simplify logic by introducing a success flag to `setSkinParts`. This eliminates unnecessary checks and reduces redundancy in message handling, improving code clarity and maintainability.
  • Loading branch information
NonSwag committed Jan 24, 2025
1 parent 2bfdf0e commit ff90cf0
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,12 @@ private static int layerToggle(CommandContext<CommandSourceStack> context, Chara
.toggle(layer, visible)
.build();

if (skinParts.equals(character.getSkinParts())) {
plugin.bundle().sendMessage(sender, "nothing.changed");
return 0;
}

character.setSkinParts(skinParts);

var message = visible ? "character.skin_layer.shown" : "character.skin_layer.hidden";
var success = character.setSkinParts(skinParts);
var message = !success ? "nothing.changed" : visible
? "character.skin_layer.shown" : "character.skin_layer.hidden";
plugin.bundle().sendMessage(sender, message,
Placeholder.component("layer", Component.translatable(layer)),
Placeholder.unparsed("character", character.getName()));

return Command.SINGLE_SUCCESS;
}

Expand Down

0 comments on commit ff90cf0

Please sign in to comment.