Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Then add dependencies:

```kotlin
dependencies {
implementation("gg.moonrise.engine:plugin-engine-paper:1.1.1")
// or: implementation("gg.moonrise.engine:plugin-engine-common:1.1.1")
implementation("gg.moonrise.engine:plugin-engine-paper:1.1.2")
// or: implementation("gg.moonrise.engine:plugin-engine-common:1.1.2")
}
```

Expand All @@ -61,7 +61,7 @@ dependencies {
<dependency>
<groupId>gg.moonrise.engine</groupId>
<artifactId>plugin-engine-paper</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -182,7 +182,7 @@ public final class ExampleMenu extends ChestMenu {
}
```

Menus are cached per-player and handled by `PlayerInventoryController`.
Menus are backed by Bukkit `InventoryHolder` instances and handled by `PlayerInventoryController`.

## Messages and placeholders

Expand Down
11 changes: 7 additions & 4 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

var id = "plugin-engine-common"
var domain = "gg.moonrise.engine"
var apiVersion = "1.1.1"
var apiVersion = "1.1.2"

repositories {
mavenCentral()
Expand Down Expand Up @@ -50,6 +50,9 @@ java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}

withSourcesJar()
withJavadocJar()
}

tasks.shadowJar {
Expand All @@ -65,9 +68,9 @@ tasks.test {
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifact(tasks.shadowJar) {
builtBy(tasks.shadowJar)
}
from(components["shadow"])
artifact(tasks.named<Jar>("sourcesJar"))
artifact(tasks.named<Jar>("javadocJar"))

groupId = domain
artifactId = id
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/gg/moonrise/engine/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static Message of(String content) {
}

/**
* Creates a Message object from multiple lines of strings, joining them with the <newline> delimiter.
* Creates a Message object from multiple lines of strings, joining them with the {@code <newline>} delimiter.
* @param lines the lines of strings to join
* @return a Message object containing the joined content
*/
Expand All @@ -33,7 +33,7 @@ public static Message of(String... lines) {
}

/**
* Creates a Message object from a list of strings, joining them with the <newline> delimiter.
* Creates a Message object from a list of strings, joining them with the {@code <newline>} delimiter.
* @param lines the list of strings to join
* @return a Message object containing the joined content
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <p>The class uses a singleton pattern for the two possible instances ({@code true} and {@code false})
* to ensure memory efficiency and reference equality for instances with the same boolean value.</p>
*
* <h3>Usage Examples:</h3>
* <h2>Usage Examples:</h2>
* <pre>{@code
* OptionalBool condition = OptionalBool.of(someCondition);
*
Expand Down Expand Up @@ -218,4 +218,3 @@ public String toString() {
return "OptionalBool[" + value + "]";
}
}

23 changes: 19 additions & 4 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

var id = "plugin-engine-paper"
var domain = "gg.moonrise.engine"
var apiVersion = "1.1.1"
var apiVersion = "1.1.2"

repositories {
mavenCentral()
Expand Down Expand Up @@ -39,12 +39,23 @@ dependencies {
// Lombok
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")

// Testing
testImplementation(platform("org.junit:junit-bom:5.12.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.76.1")
testImplementation("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
testImplementation("net.kyori:adventure-text-serializer-plain:4.26.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}

withSourcesJar()
withJavadocJar()
}

tasks.jar {
Expand All @@ -57,12 +68,16 @@ tasks.shadowJar {
archiveClassifier.set("")
}

tasks.test {
useJUnitPlatform()
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
artifact(tasks.shadowJar) {
builtBy(tasks.shadowJar)
}
from(components["shadow"])
artifact(tasks.named<Jar>("sourcesJar"))
artifact(tasks.named<Jar>("javadocJar"))

groupId = domain
artifactId = id
Expand Down
38 changes: 31 additions & 7 deletions paper/src/main/java/gg/moonrise/engine/paper/gui/ChestMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.google.common.base.Preconditions;
import gg.moonrise.engine.message.util.MiniMessageUtil;
import gg.moonrise.engine.paper.gui.button.Button;
import gg.moonrise.engine.paper.gui.holder.ChestMenuHolder;
import gg.moonrise.engine.paper.gui.util.MenuInteractionUtil;
import gg.moonrise.engine.paper.gui.util.SafeUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -20,8 +23,7 @@
/**
* Represents a chest-based GUI menu for players.
* This class manages button placement, click handling, and automatic refreshing
* of dynamic buttons. Menus are cached per-player and automatically cleaned up
* when closed.
* of dynamic buttons. Menus are routed through their inventory holder.
*/
public abstract class ChestMenu implements ChestInterface {

Expand All @@ -32,7 +34,7 @@ public abstract class ChestMenu implements ChestInterface {
private final Map<UUID, Button> buttonById = new HashMap<>();
private final Map<Integer, Button> refreshingButtons = new HashMap<>();

protected InventoryView inventory;
protected Inventory inventory;
private boolean cancelClicks = true;

private final Player player;
Expand Down Expand Up @@ -97,7 +99,7 @@ public void onOpen(Player player, InventoryOpenEvent event) {
*/
@Override
public void onClose(Player player, InventoryCloseEvent event) {
UserInterface.invalidateFromCache(player.getUniqueId());
invalidate();
}

/**
Expand All @@ -116,7 +118,7 @@ public void onClick(Player player, InventoryClickEvent event) {
*/
@Override
public void open() {
MenuInteractionUtil.openMenu(player, this, this::refresh, () -> inventory);
MenuInteractionUtil.openMenu(player, this::refresh, () -> inventory);
}

/**
Expand All @@ -135,7 +137,7 @@ public void invalidate() {
@Override
public void refresh() {
if (inventory == null)
inventory = typeFromRows(rows).create(player, title);
inventory = createInventory();

clearInventory(inventory);

Expand Down Expand Up @@ -252,13 +254,28 @@ public int getButtonCount() {
return buttons.size();
}

/**
* Get the Inventory associated with this ChestMenu
* @return The Inventory
*/
@Override
public Inventory getInventory() {
return inventory;
}

/**
* Get the InventoryView associated with this ChestMenu
* @return The InventoryView
*/
@Override
@Deprecated(forRemoval = false)
public InventoryView getView() {
return inventory;
if (inventory == null) return null;

InventoryView view = player.getOpenInventory();
if (!view.getTopInventory().equals(inventory)) return null;

return view;
}

/**
Expand Down Expand Up @@ -286,4 +303,11 @@ public boolean checkCancelClick(int slot) {
return MenuInteractionUtil.checkCancelClick(inventory, buttonById, slot);
}

private Inventory createInventory() {
ChestMenuHolder holder = new ChestMenuHolder(this);
Inventory created = Bukkit.createInventory(holder, rows * 9, title);
holder.setInventory(created);
return created;
}

}
42 changes: 33 additions & 9 deletions paper/src/main/java/gg/moonrise/engine/paper/gui/HopperMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import gg.moonrise.engine.message.util.MiniMessageUtil;
import gg.moonrise.engine.paper.gui.button.Button;
import gg.moonrise.engine.paper.gui.holder.HopperMenuHolder;
import gg.moonrise.engine.paper.gui.util.MenuInteractionUtil;
import gg.moonrise.engine.paper.gui.util.SafeUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MenuType;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Contract;

Expand All @@ -20,8 +23,7 @@
/**
* Represents a chest-based GUI menu for players.
* This class manages button placement, click handling, and automatic refreshing
* of dynamic buttons. Menus are cached per-player and automatically cleaned up
* when closed.
* of dynamic buttons. Menus are routed through their inventory holder.
*/
public abstract class HopperMenu implements UserInterface {

Expand All @@ -31,7 +33,7 @@ public abstract class HopperMenu implements UserInterface {
private final Map<UUID, Button> buttonById = new HashMap<>();
private final Map<Integer, Button> refreshingButtons = new HashMap<>();

protected InventoryView inventory;
protected Inventory inventory;
private boolean cancelClicks = true;

private final Player player;
Expand Down Expand Up @@ -81,7 +83,7 @@ public void onOpen(Player player, InventoryOpenEvent event) {
*/
@Override
public void onClose(Player player, InventoryCloseEvent event) {
UserInterface.invalidateFromCache(player.getUniqueId());
invalidate();
}

/**
Expand All @@ -100,7 +102,7 @@ public void onClick(Player player, InventoryClickEvent event) {
*/
@Override
public void open() {
MenuInteractionUtil.openMenu(player, this, this::refresh, () -> inventory);
MenuInteractionUtil.openMenu(player, this::refresh, () -> inventory);
}

/**
Expand All @@ -119,7 +121,7 @@ public void invalidate() {
@Override
public void refresh() {
if (inventory == null)
inventory = MenuType.HOPPER.create(player, title);
inventory = createInventory();

clearInventory(inventory);

Expand Down Expand Up @@ -169,7 +171,7 @@ public void addButton(int slot, Button button) {
* @param button The button to add
*/
public void addButton(Button button) {
for (int i = 0; i < inventory.getTopInventory().getSize(); i++) {
for (int i = 0; i < InventoryType.HOPPER.getDefaultSize(); i++) {
if (buttons.containsKey(i)) continue;

addButton(i, button);
Expand Down Expand Up @@ -231,13 +233,28 @@ public int getButtonCount() {
return buttons.size();
}

/**
* Get the Inventory associated with this menu
* @return The Inventory
*/
@Override
public Inventory getInventory() {
return inventory;
}

/**
* Get the InventoryView associated with this menu
* @return The InventoryView
*/
@Override
@Deprecated(forRemoval = false)
public InventoryView getView() {
return inventory;
if (inventory == null) return null;

InventoryView view = player.getOpenInventory();
if (!view.getTopInventory().equals(inventory)) return null;

return view;
}

/**
Expand Down Expand Up @@ -265,4 +282,11 @@ public boolean checkCancelClick(int slot) {
return MenuInteractionUtil.checkCancelClick(inventory, buttonById, slot);
}

private Inventory createInventory() {
HopperMenuHolder holder = new HopperMenuHolder(this);
Inventory created = Bukkit.createInventory(holder, InventoryType.HOPPER, title);
holder.setInventory(created);
return created;
}

}
Loading
Loading