outside commands feature

This commit is contained in:
rockyhawk64 2025-10-12 11:38:20 +11:00
parent 8b80ab0ed3
commit 334856a421
2 changed files with 27 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import me.rockyhawk.commandpanels.Context;
import me.rockyhawk.commandpanels.builder.PanelBuilder;
import me.rockyhawk.commandpanels.builder.inventory.InventoryPanelBuilder;
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
import me.rockyhawk.commandpanels.session.ClickActions;
import me.rockyhawk.commandpanels.session.Panel;
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
import org.bukkit.Bukkit;
@ -22,6 +23,7 @@ public class InventoryPanel extends Panel implements InventoryHolder {
private final String rows;
private final Map<String, PanelItem> items = new HashMap<>();
private final Map<String, List<String>> slots = new HashMap<>();
private final ClickActions outside;
private final String floodgate;
private final String updateDelay;
@ -32,6 +34,12 @@ public class InventoryPanel extends Panel implements InventoryHolder {
this.floodgate = config.getString("floodgate", "");
this.updateDelay = config.getString("update-delay", "20");
outside = new ClickActions(
config.getStringList("outside.requirements"),
config.getStringList("outside.commands"),
config.getStringList("outside.fail")
);
ConfigurationSection slotSection = config.getConfigurationSection("layout");
if (slotSection != null) {
for (String key : slotSection.getKeys(false)) {
@ -104,9 +112,14 @@ public class InventoryPanel extends Panel implements InventoryHolder {
return updateDelay;
}
public ClickActions getOutsideCommands() {
return outside;
}
// For InventoryHolder implementation
@Override
public Inventory getInventory() {
return null;
}
}

View File

@ -1,7 +1,6 @@
package me.rockyhawk.commandpanels.session.inventory.listeners;
import me.rockyhawk.commandpanels.Context;
import me.rockyhawk.commandpanels.formatter.language.Message;
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
import me.rockyhawk.commandpanels.session.ClickActions;
@ -33,6 +32,20 @@ public class ClickEvents implements Listener {
requirements = new RequirementRunner(ctx);
}
@EventHandler
public void onOutsideInventoryClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player player)) return;
if (e.getClickedInventory() != null) return;
if (!(player.getOpenInventory().getTopInventory().getHolder() instanceof InventoryPanel panel)) return;
ClickActions actions = panel.getOutsideCommands();
if(!requirements.processRequirements(panel, player, actions.requirements())){
commands.runCommands(panel, player, actions.fail());
return;
}
commands.runCommands(panel, player, actions.commands());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player player)) return;