-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
189 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
bukkit/src/main/java/broccolai/tags/bukkit/commands/BukkitTagsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package broccolai.tags.bukkit.commands; | ||
|
||
import broccolai.corn.paper.item.PaperItemBuilder; | ||
import broccolai.tags.api.model.tag.ConstructedTag; | ||
import broccolai.tags.api.model.tag.TagDisplayInformation; | ||
import broccolai.tags.api.model.user.TagsUser; | ||
import broccolai.tags.api.service.UserService; | ||
import broccolai.tags.bukkit.commands.context.BukkitPlayerCommandUser; | ||
import broccolai.tags.bukkit.menu.TagsMenuFactory; | ||
import broccolai.tags.core.commands.PluginCommand; | ||
import broccolai.tags.core.commands.arguments.modes.TagParserMode; | ||
import broccolai.tags.core.commands.context.CommandUser; | ||
import broccolai.tags.core.factory.CloudArgumentFactory; | ||
import cloud.commandframework.Command; | ||
import cloud.commandframework.CommandManager; | ||
import cloud.commandframework.context.CommandContext; | ||
import com.google.inject.Inject; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.interfaces.paper.PlayerViewer; | ||
|
||
public final class BukkitTagsCommand implements PluginCommand { | ||
|
||
private final UserService userService; | ||
private final CloudArgumentFactory argumentFactory; | ||
private final TagsMenuFactory tagsMenuFactory; | ||
|
||
@Inject | ||
public BukkitTagsCommand( | ||
final @NonNull UserService userService, | ||
final @NonNull CloudArgumentFactory argumentFactory, | ||
final @NonNull TagsMenuFactory tagsMenuFactory | ||
) { | ||
this.userService = userService; | ||
this.argumentFactory = argumentFactory; | ||
this.tagsMenuFactory = tagsMenuFactory; | ||
} | ||
|
||
@Override | ||
public void register(@NonNull final CommandManager<@NonNull CommandUser> commandManager) { | ||
Command.Builder<CommandUser> tagsCommand = commandManager.commandBuilder("tags"); | ||
|
||
commandManager.command(tagsCommand | ||
.literal("test-item") | ||
.permission("tags.command.admin.test-item") | ||
.argument(this.argumentFactory.tag("tag", TagParserMode.SELF)) | ||
.handler(this::handleTestItem) | ||
); | ||
|
||
commandManager.command(tagsCommand | ||
.literal("menu") | ||
.permission("tags.command.user.menu") | ||
.handler(this::handleMenu) | ||
); | ||
} | ||
|
||
private void handleTestItem(final @NonNull CommandContext<CommandUser> context) { | ||
ConstructedTag tag = context.get("tag"); | ||
TagDisplayInformation displayInformation = tag.displayInformation(); | ||
|
||
Material material = Material.matchMaterial(displayInformation.material()); | ||
|
||
ItemStack item = PaperItemBuilder | ||
.ofType(material) | ||
.customModelData(displayInformation.customModelData()) | ||
.build(); | ||
|
||
BukkitPlayerCommandUser user = context.getSender().cast(); | ||
user.player().getInventory().addItem(item); | ||
} | ||
|
||
private void handleMenu(final @NonNull CommandContext<CommandUser> context) { | ||
BukkitPlayerCommandUser sender = context.getSender().cast(); | ||
TagsUser user = this.userService.get(sender.uuid()); | ||
|
||
this.tagsMenuFactory.create(user).open(PlayerViewer.of(sender.player())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
bukkit/src/main/java/broccolai/tags/bukkit/menu/TagsMenuFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package broccolai.tags.bukkit.menu; | ||
|
||
import broccolai.corn.paper.item.PaperItemBuilder; | ||
import broccolai.tags.api.model.tag.ConstructedTag; | ||
import broccolai.tags.api.model.user.TagsUser; | ||
import broccolai.tags.api.service.TagsService; | ||
import com.google.inject.Inject; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.interfaces.core.transform.types.PaginatedTransform; | ||
import org.incendo.interfaces.core.util.Vector2; | ||
import org.incendo.interfaces.paper.PlayerViewer; | ||
import org.incendo.interfaces.paper.element.ItemStackElement; | ||
import org.incendo.interfaces.paper.pane.ChestPane; | ||
import org.incendo.interfaces.paper.type.ChestInterface; | ||
|
||
import java.util.List; | ||
|
||
public final class TagsMenuFactory { | ||
|
||
private final TagsService tagsService; | ||
|
||
@Inject | ||
public TagsMenuFactory(final @NonNull TagsService tagsService) { | ||
this.tagsService = tagsService; | ||
} | ||
|
||
public ChestInterface create(final @NonNull TagsUser user) { | ||
return ChestInterface.builder() | ||
.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), | ||
() -> this.createTagElements(user) | ||
); | ||
} | ||
|
||
private List<ItemStackElement<ChestPane>> createTagElements(final @NonNull TagsUser user) { | ||
return this.tagsService.allTags(user) | ||
.stream() | ||
.map(this::createTagElement) | ||
.toList(); | ||
} | ||
|
||
private ItemStackElement<ChestPane> createTagElement(final @NonNull ConstructedTag tag) { | ||
Material material = Material.matchMaterial(tag.displayInformation().material()); | ||
ItemStack item = PaperItemBuilder.ofType(material) | ||
.name(tag.component()) | ||
.build(); | ||
|
||
return ItemStackElement.of(item); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters