diff --git a/api/src/main/java/broccolai/tags/api/model/tag/ConstructedTag.java b/api/src/main/java/broccolai/tags/api/model/tag/ConstructedTag.java index f23799a..ecb3798 100644 --- a/api/src/main/java/broccolai/tags/api/model/tag/ConstructedTag.java +++ b/api/src/main/java/broccolai/tags/api/model/tag/ConstructedTag.java @@ -5,58 +5,18 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public final class ConstructedTag implements Permissible { - - private final int id; - private final String name; - private final boolean secret; - private final @NonNull Component component; - private final @NonNull String reason; - private final @Nullable TagDisplayInformation displayInformation; - - public ConstructedTag( - final int id, - final @NonNull String name, - final boolean secret, - final @NonNull Component component, - final @NonNull String reason, - final @Nullable TagDisplayInformation displayInformation - ) { - this.id = id; - this.name = name; - this.secret = secret; - this.component = component; - this.reason = reason; - this.displayInformation = displayInformation; - } - - public int id() { - return this.id; - } - - public @NonNull String name() { - return this.name; - } - - public boolean secret() { - return this.secret; - } - - public @NonNull Component component() { - return this.component; - } - - public @NonNull String reason() { - return this.reason; - } +public record ConstructedTag( + int id, + @NonNull String name, + boolean secret, + @NonNull Component component, + @NonNull String reason, + @NonNull TagDisplayInformation displayInformation +) implements Permissible { @Override public @NonNull String permission() { return "tags.tag." + this.id(); } - public @Nullable TagDisplayInformation displayInformation() { - return this.displayInformation; - } - } diff --git a/bukkit/src/main/java/broccolai/tags/bukkit/inject/PlatformModule.java b/bukkit/src/main/java/broccolai/tags/bukkit/inject/PlatformModule.java index 24f470e..2cb2658 100644 --- a/bukkit/src/main/java/broccolai/tags/bukkit/inject/PlatformModule.java +++ b/bukkit/src/main/java/broccolai/tags/bukkit/inject/PlatformModule.java @@ -11,6 +11,7 @@ import com.google.inject.AbstractModule; import org.bukkit.plugin.Plugin; import org.checkerframework.checker.nullness.qual.NonNull; +import org.slf4j.Logger; import java.io.File; @@ -27,6 +28,7 @@ protected void configure() { this.bind(Plugin.class).toInstance(this.plugin); this.bind(TagsPlatform.class).toInstance(this.plugin); this.bind(File.class).toInstance(this.plugin.getDataFolder()); + this.bind(Logger.class).toInstance(this.plugin.getSLF4JLogger()); this.bind(TaskService.class).to(BukkitTaskService.class); this.bind(UserService.class).to(BukkitPipelineUserService.class); this.bind(PermissionService.class).to(BukkitPermissionService.class); diff --git a/bukkit/src/main/java/broccolai/tags/bukkit/menu/TagsMenuFactory.java b/bukkit/src/main/java/broccolai/tags/bukkit/menu/TagsMenuFactory.java index cf2eb74..771a97f 100644 --- a/bukkit/src/main/java/broccolai/tags/bukkit/menu/TagsMenuFactory.java +++ b/bukkit/src/main/java/broccolai/tags/bukkit/menu/TagsMenuFactory.java @@ -14,20 +14,27 @@ import org.incendo.interfaces.paper.element.ItemStackElement; import org.incendo.interfaces.paper.pane.ChestPane; import org.incendo.interfaces.paper.type.ChestInterface; +import org.slf4j.Logger; import java.util.List; public final class TagsMenuFactory { + private final Logger logger; private final TagsService tagsService; @Inject - public TagsMenuFactory(final @NonNull TagsService tagsService) { + public TagsMenuFactory( + final @NonNull Logger logger, + final @NonNull TagsService tagsService + ) { + this.logger = logger; this.tagsService = tagsService; } public ChestInterface create(final @NonNull TagsUser user) { return ChestInterface.builder() + .rows(4) .addReactiveTransform(this.createTagTransform(user)) .build(); } @@ -35,7 +42,7 @@ public ChestInterface create(final @NonNull TagsUser user) { private PaginatedTransform, ChestPane, PlayerViewer> createTagTransform(final @NonNull TagsUser user) { return new PaginatedTransform<>( Vector2.at(0, 0), - Vector2.at(3, 8), + Vector2.at(8, 3), () -> this.createTagElements(user) ); } @@ -48,7 +55,7 @@ private List> createTagElements(final @NonNull TagsU } private ItemStackElement createTagElement(final @NonNull ConstructedTag tag) { - Material material = Material.matchMaterial(tag.displayInformation().material()); + Material material = matchMaterialOrDefault(tag.displayInformation().material()); ItemStack item = PaperItemBuilder.ofType(material) .name(tag.component()) .build(); @@ -56,4 +63,15 @@ private ItemStackElement createTagElement(final @NonNull ConstructedT return ItemStackElement.of(item); } + private Material matchMaterialOrDefault(final @NonNull String input) { + Material material = Material.matchMaterial(input); + + if (material == null) { + this.logger.warn("material {} does not exist", input); + material = Material.POTATO; + } + + return material; + } + } diff --git a/core/src/main/java/broccolai/tags/core/config/MainConfiguration.java b/core/src/main/java/broccolai/tags/core/config/MainConfiguration.java index 6c60992..f0cf848 100644 --- a/core/src/main/java/broccolai/tags/core/config/MainConfiguration.java +++ b/core/src/main/java/broccolai/tags/core/config/MainConfiguration.java @@ -28,10 +28,21 @@ public final class MainConfiguration implements Configuration { @Setting @Comment( - "Potential tags for players to obtain. \n" - + "Increment id for each new tag, if you remove a tag, treat the config as if it's id is still there. \n" - + "Permissions will use this id as it's reference. \n" - + "The name attribute should be a simple one word phrase for selecting tags through commands." + """ + Potential tags for players to obtain. + Increment id for each new tag, if you remove a tag, treat the config as if it's id is still there. + Permissions will use this id as it's reference. + The name attribute should be a simple one word phrase for selecting tags through commands. + + Tag configuration is described as followed: + id -> the unique numerical id for tags + name -> the unique name for a tag to be used in a command + component -> the component to be rendered in chat / menu first line + reason -> how a player could obtain the tag + display-information: + material -> the material id to use for the menu representation + custom-model-data -> the custom model id to use on items, optionally + """ ) public List tags = new ArrayList<>() {{ this.add(new TagConfiguration( diff --git a/core/src/main/java/broccolai/tags/core/config/TagConfiguration.java b/core/src/main/java/broccolai/tags/core/config/TagConfiguration.java index e1929b5..98abe8b 100644 --- a/core/src/main/java/broccolai/tags/core/config/TagConfiguration.java +++ b/core/src/main/java/broccolai/tags/core/config/TagConfiguration.java @@ -11,27 +11,25 @@ public final class TagConfiguration { @Setting - @Comment("Tags unique id") public int id; @Setting - @Comment("Readable name for players") public String name; @Setting - @Comment("Whether to hide the tag from public info") public boolean secret = false; @Setting - @Comment("MiniMessage component to display") public String component; @Setting - @Comment("How to obtain this tag, can be null") public String reason = null; @Setting - public TagDisplayInformation displayInformation = null; + public TagDisplayInformation displayInformation = new TagDisplayInformation( + "stick", + 0 + ); public TagConfiguration() { }