Compare commits
No commits in common. "d0398b14865b3b4bf6d304d4792478c535bc3d20" and "813d76b99292d63a3be8b29f53dcd2f68b552bb1" have entirely different histories.
d0398b1486
...
813d76b992
|
|
@ -9,7 +9,7 @@ val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: Syst
|
||||||
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
|
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
|
||||||
|
|
||||||
group = "com.alttd.inventory_gui"
|
group = "com.alttd.inventory_gui"
|
||||||
version = "1.1.3-SNAPSHOT"
|
version = "1.1.1-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.*;
|
import org.bukkit.event.inventory.*;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code GuiListener} class implements the {@code Listener} interface to handle
|
* The {@code GuiListener} class implements the {@code Listener} interface to handle
|
||||||
|
|
@ -23,10 +22,14 @@ import java.util.Optional;
|
||||||
@SuppressWarnings("ClassCanBeRecord")
|
@SuppressWarnings("ClassCanBeRecord")
|
||||||
public final class GuiListener implements Listener {
|
public final class GuiListener implements Listener {
|
||||||
|
|
||||||
|
private final String ownerPluginName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new {@code GuiListener} instance.
|
* Constructs a new {@code GuiListener} instance.
|
||||||
|
* @param ownerPluginName the name of the plugin that owns the GUI instances to which this listener should be attached
|
||||||
*/
|
*/
|
||||||
public GuiListener() {
|
public GuiListener(String ownerPluginName) {
|
||||||
|
this.ownerPluginName = ownerPluginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,14 +46,14 @@ public final class GuiListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<GuiSession.Entry> optionalEntry = getEntry(player, event.getInventory());
|
GuiSession.Entry entry = getEntry(player, event.getInventory());
|
||||||
if (optionalEntry.isEmpty()) {
|
if (entry == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (event instanceof InventoryClickEvent inventoryClickEvent) {
|
if (event instanceof InventoryClickEvent inventoryClickEvent) {
|
||||||
optionalEntry.get().gui().handleClick(inventoryClickEvent);
|
entry.gui().handleClick(inventoryClickEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,20 +67,26 @@ public final class GuiListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<GuiSession.Entry> optionalEntry = getEntry(player, event.getInventory());
|
GuiSession.Entry entry = getEntry(player, event.getInventory());
|
||||||
if (optionalEntry.isEmpty()) {
|
if (entry == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
optionalEntry.get().gui().handleClose(player);
|
entry.gui().handleClose(player);
|
||||||
GuiSession.clear(player.getUniqueId());
|
GuiSession.clear(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<GuiSession.Entry> getEntry(Player player, Inventory event) {
|
private GuiSession.@Nullable Entry getEntry(Player player, Inventory event) {
|
||||||
GuiSession.Entry entry = GuiSession.get(player.getUniqueId());
|
GuiSession.Entry entry = GuiSession.get(player.getUniqueId());
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return Optional.empty();
|
return null;
|
||||||
}
|
}
|
||||||
return Optional.of(entry);
|
if (!entry.ownerPluginName().equals(ownerPluginName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (event != entry.inv()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import com.alttd.inventory_gui.pane.SimplePane;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
@ -25,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
* This class is built with flexibility and ease of use in mind, supporting various
|
* This class is built with flexibility and ease of use in mind, supporting various
|
||||||
* customization options, event handling, and row validation to maintain consistency.
|
* customization options, event handling, and row validation to maintain consistency.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@Builder
|
@Builder
|
||||||
public class InventoryGui {
|
public class InventoryGui {
|
||||||
|
|
||||||
|
|
@ -71,25 +69,11 @@ public class InventoryGui {
|
||||||
* Renders the GUI's contents into the specified inventory.
|
* Renders the GUI's contents into the specified inventory.
|
||||||
* @param inv the inventory into which to render the GUI's contents
|
* @param inv the inventory into which to render the GUI's contents
|
||||||
*/
|
*/
|
||||||
protected void render(Inventory inv) {
|
public void render(Inventory inv) {
|
||||||
inv.clear();
|
inv.clear();
|
||||||
root.render(inv);
|
root.render(inv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the GUI's contents into the open inventory of the specified human entity if it exists.
|
|
||||||
* @param humanEntity the human entity for which to render the GUI's contents
|
|
||||||
*/
|
|
||||||
public void render(HumanEntity humanEntity) {
|
|
||||||
GuiSession.Entry entry = GuiSession.get(humanEntity.getUniqueId());
|
|
||||||
if (entry == null) {
|
|
||||||
log.warn("No GUI session found for player {} during render", humanEntity.getName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory inv = entry.inv();
|
|
||||||
render(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the GUI for the specified human entity.
|
* Opens the GUI for the specified human entity.
|
||||||
* @param humanEntity the human entity for whom to open the GUI
|
* @param humanEntity the human entity for whom to open the GUI
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public final class InventoryGuiLib {
|
||||||
Objects.requireNonNull(plugin, "plugin cannot be null");
|
Objects.requireNonNull(plugin, "plugin cannot be null");
|
||||||
|
|
||||||
REGISTRATIONS.computeIfAbsent(plugin.getName(), name -> {
|
REGISTRATIONS.computeIfAbsent(plugin.getName(), name -> {
|
||||||
Listener listener = new GuiListener();
|
Listener listener = new GuiListener(name);
|
||||||
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||||
return new Registration(plugin, listener);
|
return new Registration(plugin, listener);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user