Skip to content

Commit

Permalink
feature: more work on gui
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolai committed Oct 19, 2023
1 parent e8474fc commit 572f044
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 61 deletions.
56 changes: 8 additions & 48 deletions api/src/main/java/broccolai/tags/api/model/tag/ConstructedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@
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();
}

private PaginatedTransform<ItemStackElement<ChestPane>, 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)
);
}
Expand All @@ -48,12 +55,23 @@ private List<ItemStackElement<ChestPane>> createTagElements(final @NonNull TagsU
}

private ItemStackElement<ChestPane> 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();

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagConfiguration> tags = new ArrayList<>() {{
this.add(new TagConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down

0 comments on commit 572f044

Please sign in to comment.