Skip to content

Commit

Permalink
Add example command from documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Jul 5, 2024
1 parent f7db711 commit 9ef683e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.nookure.core.inv;

import com.nookure.core.inv.paper.PaperNookureInventoryEngine;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class ExampleCommand extends Command {
private final PaperNookureInventoryEngine engine;

protected ExampleCommand(@NotNull PaperNookureInventoryEngine engine) {
super("example");
this.engine = engine;
}

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (sender instanceof Player player) {
engine.openAsync(player, "our-first-gui.xml");
return true;
}

sender.sendRichMessage("<red>You are the console!");
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void onEnable() {
saveResource("gui/PaginationTest.peb", true);
saveResource("gui/PaginationCommon.peb", true);
saveResource("gui/PlayerPaginationTest.peb", true);
saveResource("gui/our-first-gui.xml", false);

engine = new PaperNookureInventoryEngine.Builder()
.templateFolder("gui")
Expand All @@ -34,6 +35,7 @@ public void onEnable() {
.build();

CommandMap commandMap = Bukkit.getServer().getCommandMap();
commandMap.register("nookure", new ExampleCommand(engine));

commandMap.register("nookure", new Command("test") {
@Override
Expand Down
60 changes: 60 additions & 0 deletions NookureInventory-Test/src/main/resources/gui/our-first-gui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- This is the root element of *ALL* inventories -->
<GuiLayout>
<!--
This is the head of the inventory, here you can set the title and the rows of the inventory
Something similar to the <head> tag in HTML 🤔
-->
<Head>
<!--
Here you define the title of the inventory, the title will be parsed by the MiniMessage library
so you can use the MiniMessage format here, but for limitations of the XML format, you need to
use [ instead of < and ] instead of >
-->
<title>
[#FF6545] Your awesome inventory
</title>
<!--
Here you define the rows of the inventory, you can set the rows to 1-6
-->
<rows>1</rows>
</Head>
<!--
This is the items element, this is the container of all items in the inventory
-->
<Items>
<!--
This is the item element, here you define the item that will be in the inventory
We have a lot of attributes that you can use here, in this case, we are using
the slot and material
attributes
slot: The slot where the item will be placed in the inventory, you can use 0-53,
each row has 9 slots but remember that arrays start at 0, so the first slot
is 0
material: The material of the item, you can use the material name or the material
id this should be present in the
Material enum https://jd.papermc.io/paper/1.21/org/bukkit/Material.html
-->
<Item
slot="4"
material="STONE"
>
<!--
This is the name of the item, here you can set the name of the item
The name will be parsed by the MiniMessage library
Just like the title, you need to use [ instead of < and ] instead of >
-->
<Name>
[red]Magic Stone ✨[/red]
</Name>
<!--
This is the lore of the item, here you can set the lore of the item
The lore will be parsed by the MiniMessage library
Just like the title, you need to use [ instead of < and ] instead of >
-->
<LiteralLore>
This is a magic stone
[red]It's very powerful[/red]
</LiteralLore>
</Item>
</Items>
</GuiLayout>

0 comments on commit 9ef683e

Please sign in to comment.