mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
outside commands feature
This commit is contained in:
parent
8b80ab0ed3
commit
334856a421
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user