Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.feeliiix.fundamental.api.message.style;
- import static com.feeliiix.fundamental.api.util.PreconditionAdditions.checkNotEmpty;
- import static com.google.common.base.Preconditions.checkArgument;
- import static com.google.common.base.Preconditions.checkNotNull;
- import org.spongepowered.api.CatalogType;
- import org.spongepowered.api.text.format.TextColor;
- import org.spongepowered.api.text.format.TextStyle;
- import org.spongepowered.api.util.ResettableBuilder;
- import java.util.List;
- import java.util.Optional;
- public class MessageStyle implements CatalogType {
- private final String id;
- private final String name;
- private final Optional<TextColor> prefixColor;
- private final Optional<List<TextStyle>> prefixStyles;
- private final Optional<TextColor> textColor;
- private final Optional<List<TextStyle>> textStyles;
- public MessageStyle(String id, String name, TextColor prefixColor, List<TextStyle> prefixStyle, TextColor textColor, List<TextStyle> textStyles){
- this.id = checkNotNull(id);
- this.name = checkNotNull(name);
- this.prefixColor = Optional.ofNullable(prefixColor);
- this.prefixStyles = Optional.ofNullable(prefixStyle);
- this.textColor = Optional.ofNullable(textColor);
- this.textStyles = Optional.ofNullable(textStyles);
- if(this.prefixStyles.isPresent()) checkNotEmpty(this.prefixStyles.get());
- if(this.textStyles.isPresent()) checkNotEmpty(this.textStyles.get());
- }
- @Override
- public String getId() {
- return this.id;
- }
- @Override
- public String getName() {
- return this.name;
- }
- public Optional<TextColor> getPrefixColor() {
- return this.prefixColor;
- }
- public Optional<List<TextStyle>> getPrefixStyles() {
- return this.prefixStyles;
- }
- public Optional<TextColor> getTextColor() {
- return this.textColor;
- }
- public Optional<List<TextStyle>> getTextStyles() {
- return this.textStyles;
- }
- public static Builder builder() {
- return new Builder();
- }
- public static class Builder implements ResettableBuilder<MessageStyle, Builder> {
- private String id;
- private String name;
- private TextColor prefixColor;
- private List<TextStyle> prefixStyles;
- private TextColor textColor;
- private List<TextStyle> textStyles;
- private Builder() {}
- public Builder id(String id) {
- this.id = checkNotNull(id);
- return this;
- }
- public Builder name(String name) {
- this.name = checkNotNull(name);
- return this;
- }
- public Builder prefixColor(TextColor prefixColor) {
- this.prefixColor = prefixColor;
- return this;
- }
- public Builder prefixStyles(List<TextStyle> prefixStyles) {
- this.prefixStyles = prefixStyles;
- return this;
- }
- public Builder textColor(TextColor textColor) {
- this.textColor = textColor;
- return this;
- }
- public Builder textStyles(List<TextStyle> textStyles) {
- this.textStyles = textStyles;
- return this;
- }
- @Override
- public Builder from(MessageStyle messageStyle) {
- this.id = messageStyle.id;
- this.name = messageStyle.name;
- this.prefixColor = messageStyle.prefixColor.orElse(null);
- this.prefixStyles = messageStyle.prefixStyles.orElse(null);
- this.textColor = messageStyle.textColor.orElse(null);
- this.textStyles = messageStyle.textStyles.orElse(null);
- return this;
- }
- @Override
- public Builder reset() {
- this.id = null;
- this.name = null;
- this.prefixColor = null;
- this.prefixStyles = null;
- this.textColor = null;
- this.textStyles = null;
- return this;
- }
- public MessageStyle build() {
- checkArgument(this.id != null);
- checkArgument(this.name != null);
- return new MessageStyle(this.id, this.name, this.prefixColor, this.prefixStyles, this.textColor, this.textStyles);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement