mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
added close commands and new open command layout
This commit is contained in:
parent
484a1a6ed3
commit
2eaedcb704
@ -7,7 +7,7 @@ import me.rockyhawk.commandpanels.builder.logic.ConditionNode;
|
|||||||
import me.rockyhawk.commandpanels.builder.logic.ConditionParser;
|
import me.rockyhawk.commandpanels.builder.logic.ConditionParser;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.dialog.DialogComponent;
|
import me.rockyhawk.commandpanels.session.dialog.DialogComponent;
|
||||||
import me.rockyhawk.commandpanels.session.dialog.DialogPanel;
|
import me.rockyhawk.commandpanels.session.dialog.DialogPanel;
|
||||||
import me.rockyhawk.commandpanels.session.dialog.components.DialogButton;
|
import me.rockyhawk.commandpanels.session.dialog.components.DialogButton;
|
||||||
@ -40,7 +40,7 @@ public class ActionBuilder implements Listener {
|
|||||||
Component tooltip = ctx.text.parseTextToComponent(player, button.getTooltip());
|
Component tooltip = ctx.text.parseTextToComponent(player, button.getTooltip());
|
||||||
|
|
||||||
DialogAction action = DialogAction.customClick((options, audience) -> {
|
DialogAction action = DialogAction.customClick((options, audience) -> {
|
||||||
ClickActions actions = button.getClickActions();
|
CommandActions actions = button.getClickActions();
|
||||||
CommandRunner commands = new CommandRunner(ctx);
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
RequirementRunner requirements = new RequirementRunner(ctx);
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import me.rockyhawk.commandpanels.builder.logic.ConditionParser;
|
|||||||
import me.rockyhawk.commandpanels.formatter.language.Message;
|
import me.rockyhawk.commandpanels.formatter.language.Message;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
||||||
import me.rockyhawk.commandpanels.session.floodgate.components.FloodgateButton;
|
import me.rockyhawk.commandpanels.session.floodgate.components.FloodgateButton;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -72,7 +72,7 @@ public class SimpleForm {
|
|||||||
if (clickedButtonId >= buttonList.size()) return;
|
if (clickedButtonId >= buttonList.size()) return;
|
||||||
|
|
||||||
// Run commands
|
// Run commands
|
||||||
ClickActions actions = buttonList.get(clickedButtonId).getClickActions();
|
CommandActions actions = buttonList.get(clickedButtonId).getClickActions();
|
||||||
CommandRunner commands = new CommandRunner(ctx);
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
RequirementRunner requirements = new RequirementRunner(ctx);
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
|
|
||||||
|
|||||||
@ -4,14 +4,14 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record ClickActions(
|
public record CommandActions(
|
||||||
List<String> requirements,
|
List<String> requirements,
|
||||||
List<String> commands,
|
List<String> commands,
|
||||||
List<String> fail
|
List<String> fail
|
||||||
) {
|
) {
|
||||||
public static ClickActions fromSection(ConfigurationSection section) {
|
public static CommandActions fromSection(ConfigurationSection section) {
|
||||||
if (section == null) return new ClickActions(List.of(), List.of(), List.of());
|
if (section == null) return new CommandActions(List.of(), List.of(), List.of());
|
||||||
return new ClickActions(
|
return new CommandActions(
|
||||||
section.getStringList("requirements"),
|
section.getStringList("requirements"),
|
||||||
section.getStringList("commands"),
|
section.getStringList("commands"),
|
||||||
section.getStringList("fail")
|
section.getStringList("fail")
|
||||||
@ -23,7 +23,8 @@ public abstract class Panel {
|
|||||||
private final List<String> observedPerms; // List of permissions used in conditions for a panel
|
private final List<String> observedPerms; // List of permissions used in conditions for a panel
|
||||||
private final String command; // Command used to open the panel
|
private final String command; // Command used to open the panel
|
||||||
private final List<String> aliases; // Aliases for command that opens the panel
|
private final List<String> aliases; // Aliases for command that opens the panel
|
||||||
private final List<String> commands; // Commands that run when panel is opened
|
private final List<String> commands; // DEPRECATED OLD COMMANDS LAYOUT
|
||||||
|
private final CommandActions open; // Commands that run when panel is opened
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
public Panel(String name, YamlConfiguration config) {
|
public Panel(String name, YamlConfiguration config) {
|
||||||
@ -32,9 +33,15 @@ public abstract class Panel {
|
|||||||
this.title = config.getString("title", "Panel");
|
this.title = config.getString("title", "Panel");
|
||||||
this.command = config.getString("command", "");
|
this.command = config.getString("command", "");
|
||||||
this.aliases = config.getStringList("aliases");
|
this.aliases = config.getStringList("aliases");
|
||||||
this.commands = config.getStringList("commands");
|
this.commands = config.getStringList("commands"); // DEPRECATED OLD COMMANDS
|
||||||
this.type = config.getString("type", "inventory");
|
this.type = config.getString("type", "inventory");
|
||||||
this.observedPerms = new ArrayList<>();
|
this.observedPerms = new ArrayList<>();
|
||||||
|
|
||||||
|
open = new CommandActions(
|
||||||
|
config.getStringList("open.requirements"),
|
||||||
|
config.getStringList("open.commands"),
|
||||||
|
config.getStringList("open.fail")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check run for permission checks with commands
|
// Check run for permission checks with commands
|
||||||
@ -103,10 +110,15 @@ public abstract class Panel {
|
|||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEPRECATED OLD COMMANDS
|
||||||
public List<String> getCommands() {
|
public List<String> getCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandActions getOpenCommands() {
|
||||||
|
return open;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package me.rockyhawk.commandpanels.session.dialog;
|
package me.rockyhawk.commandpanels.session.dialog;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.dialog.components.*;
|
import me.rockyhawk.commandpanels.session.dialog.components.*;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
@ -9,14 +9,14 @@ public abstract class DialogComponent {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String conditions;
|
private final String conditions;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final ClickActions actions;
|
private final CommandActions actions;
|
||||||
|
|
||||||
public DialogComponent(String id, ConfigurationSection config) {
|
public DialogComponent(String id, ConfigurationSection config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.conditions = config.getString("conditions", "");
|
this.conditions = config.getString("conditions", "");
|
||||||
this.name = config.getString("name", "");
|
this.name = config.getString("name", "");
|
||||||
this.type = config.getString("type", "button");
|
this.type = config.getString("type", "button");
|
||||||
this.actions = ClickActions.fromSection(config.getConfigurationSection("actions"));
|
this.actions = CommandActions.fromSection(config.getConfigurationSection("actions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DialogComponent fromSection(String id, ConfigurationSection section) {
|
public static DialogComponent fromSection(String id, ConfigurationSection section) {
|
||||||
@ -48,7 +48,7 @@ public abstract class DialogComponent {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickActions getClickActions() {
|
public CommandActions getClickActions() {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,8 +4,12 @@ import me.rockyhawk.commandpanels.Context;
|
|||||||
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.builder.dialog.DialogPanelBuilder;
|
import me.rockyhawk.commandpanels.builder.dialog.DialogPanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.Panel;
|
import me.rockyhawk.commandpanels.session.Panel;
|
||||||
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -70,9 +74,25 @@ public class DialogPanel extends Panel {
|
|||||||
}
|
}
|
||||||
updatePanelData(ctx, player);
|
updatePanelData(ctx, player);
|
||||||
|
|
||||||
|
// RUN DEPRECATED PANEL COMMANDS; WILL BE REMOVED SOON
|
||||||
|
CommandRunner runnerOld = new CommandRunner(ctx);
|
||||||
|
if(!this.getCommands().isEmpty()){
|
||||||
|
if(player.hasPermission("commandpanels.command.reload"))
|
||||||
|
player.sendMessage(
|
||||||
|
Component.text("[CommandPanels] Commands is now deprecated, use new layout Open Commands instead.",
|
||||||
|
NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
runnerOld.runCommands(this, player, this.getCommands());
|
||||||
|
|
||||||
// Run panel commands
|
// Run panel commands
|
||||||
CommandRunner runner = new CommandRunner(ctx);
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
runner.runCommands(this, player, this.getCommands());
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
|
CommandActions actions = this.getOpenCommands();
|
||||||
|
if(!requirements.processRequirements(this, player, actions.requirements())){
|
||||||
|
commands.runCommands(this, player, actions.fail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands.runCommands(this, player, actions.commands());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build and open panel
|
// Build and open panel
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package me.rockyhawk.commandpanels.session.floodgate;
|
package me.rockyhawk.commandpanels.session.floodgate;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.floodgate.components.*;
|
import me.rockyhawk.commandpanels.session.floodgate.components.*;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
@ -9,14 +9,14 @@ public abstract class FloodgateComponent {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String conditions;
|
private final String conditions;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final ClickActions actions;
|
private final CommandActions actions;
|
||||||
|
|
||||||
public FloodgateComponent(String id, ConfigurationSection config) {
|
public FloodgateComponent(String id, ConfigurationSection config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.conditions = config.getString("conditions", "");
|
this.conditions = config.getString("conditions", "");
|
||||||
this.name = config.getString("name", "");
|
this.name = config.getString("name", "");
|
||||||
this.type = config.getString("type", "button");
|
this.type = config.getString("type", "button");
|
||||||
this.actions = ClickActions.fromSection(config.getConfigurationSection("actions"));
|
this.actions = CommandActions.fromSection(config.getConfigurationSection("actions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FloodgateComponent fromSection(String id, ConfigurationSection section) {
|
public static FloodgateComponent fromSection(String id, ConfigurationSection section) {
|
||||||
@ -48,7 +48,7 @@ public abstract class FloodgateComponent {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickActions getClickActions() {
|
public CommandActions getClickActions() {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,7 +4,11 @@ import me.rockyhawk.commandpanels.Context;
|
|||||||
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.builder.floodgate.FloodgatePanelBuilder;
|
import me.rockyhawk.commandpanels.builder.floodgate.FloodgatePanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.Panel;
|
import me.rockyhawk.commandpanels.session.Panel;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -60,9 +64,25 @@ public class FloodgatePanel extends Panel {
|
|||||||
}
|
}
|
||||||
updatePanelData(ctx, player);
|
updatePanelData(ctx, player);
|
||||||
|
|
||||||
|
// RUN DEPRECATED PANEL COMMANDS; WILL BE REMOVED SOON
|
||||||
|
CommandRunner runnerOld = new CommandRunner(ctx);
|
||||||
|
if(!this.getCommands().isEmpty()){
|
||||||
|
if(player.hasPermission("commandpanels.command.reload"))
|
||||||
|
player.sendMessage(
|
||||||
|
Component.text("[CommandPanels] Commands is now deprecated, use new layout Open Commands instead.",
|
||||||
|
NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
runnerOld.runCommands(this, player, this.getCommands());
|
||||||
|
|
||||||
// Run panel commands
|
// Run panel commands
|
||||||
CommandRunner runner = new CommandRunner(ctx);
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
runner.runCommands(this, player, this.getCommands());
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
|
CommandActions actions = this.getOpenCommands();
|
||||||
|
if(!requirements.processRequirements(this, player, actions.requirements())){
|
||||||
|
commands.runCommands(this, player, actions.fail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands.runCommands(this, player, actions.commands());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build and open panel
|
// Build and open panel
|
||||||
|
|||||||
@ -4,9 +4,12 @@ import me.rockyhawk.commandpanels.Context;
|
|||||||
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
import me.rockyhawk.commandpanels.builder.PanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.builder.inventory.InventoryPanelBuilder;
|
import me.rockyhawk.commandpanels.builder.inventory.InventoryPanelBuilder;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.Panel;
|
import me.rockyhawk.commandpanels.session.Panel;
|
||||||
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
import me.rockyhawk.commandpanels.session.floodgate.FloodgatePanel;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -23,7 +26,8 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
|||||||
private final String rows;
|
private final String rows;
|
||||||
private final Map<String, PanelItem> items = new HashMap<>();
|
private final Map<String, PanelItem> items = new HashMap<>();
|
||||||
private final Map<String, List<String>> slots = new HashMap<>();
|
private final Map<String, List<String>> slots = new HashMap<>();
|
||||||
private final ClickActions outside;
|
private final CommandActions outside;
|
||||||
|
private final CommandActions close;
|
||||||
private final String floodgate;
|
private final String floodgate;
|
||||||
private final String inventoryLock;
|
private final String inventoryLock;
|
||||||
private final String updateDelay;
|
private final String updateDelay;
|
||||||
@ -36,11 +40,16 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
|||||||
this.updateDelay = config.getString("update-delay", "20");
|
this.updateDelay = config.getString("update-delay", "20");
|
||||||
this.inventoryLock = config.getString("inventory-lock", "false");
|
this.inventoryLock = config.getString("inventory-lock", "false");
|
||||||
|
|
||||||
outside = new ClickActions(
|
outside = new CommandActions(
|
||||||
config.getStringList("outside.requirements"),
|
config.getStringList("outside.requirements"),
|
||||||
config.getStringList("outside.commands"),
|
config.getStringList("outside.commands"),
|
||||||
config.getStringList("outside.fail")
|
config.getStringList("outside.fail")
|
||||||
);
|
);
|
||||||
|
close = new CommandActions(
|
||||||
|
config.getStringList("close.requirements"),
|
||||||
|
config.getStringList("close.commands"),
|
||||||
|
config.getStringList("close.fail")
|
||||||
|
);
|
||||||
|
|
||||||
ConfigurationSection slotSection = config.getConfigurationSection("layout");
|
ConfigurationSection slotSection = config.getConfigurationSection("layout");
|
||||||
if (slotSection != null) {
|
if (slotSection != null) {
|
||||||
@ -82,9 +91,26 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
updatePanelData(ctx, player);
|
updatePanelData(ctx, player);
|
||||||
|
|
||||||
|
// RUN DEPRECATED PANEL COMMANDS; WILL BE REMOVED SOON
|
||||||
|
CommandRunner runnerOld = new CommandRunner(ctx);
|
||||||
|
if(!this.getCommands().isEmpty()){
|
||||||
|
if(player.hasPermission("commandpanels.command.reload"))
|
||||||
|
player.sendMessage(
|
||||||
|
Component.text("[CommandPanels] Commands is now deprecated, use new layout Open Commands instead.",
|
||||||
|
NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
runnerOld.runCommands(this, player, this.getCommands());
|
||||||
|
|
||||||
|
|
||||||
// Run panel commands
|
// Run panel commands
|
||||||
CommandRunner runner = new CommandRunner(ctx);
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
runner.runCommands(this, player, this.getCommands());
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
|
CommandActions actions = this.getOpenCommands();
|
||||||
|
if(!requirements.processRequirements(this, player, actions.requirements())){
|
||||||
|
commands.runCommands(this, player, actions.fail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands.runCommands(this, player, actions.commands());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build and open the panel
|
// Build and open the panel
|
||||||
@ -114,10 +140,14 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
|||||||
return updateDelay;
|
return updateDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickActions getOutsideCommands() {
|
public CommandActions getOutsideCommands() {
|
||||||
return outside;
|
return outside;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandActions getCloseCommands() {
|
||||||
|
return close;
|
||||||
|
}
|
||||||
|
|
||||||
public String getInventoryLock() {
|
public String getInventoryLock() {
|
||||||
return inventoryLock;
|
return inventoryLock;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package me.rockyhawk.commandpanels.session.inventory;
|
package me.rockyhawk.commandpanels.session.inventory;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
@ -16,11 +16,11 @@ public record PanelItem(
|
|||||||
String tooltip,
|
String tooltip,
|
||||||
String animate,
|
String animate,
|
||||||
String conditions,
|
String conditions,
|
||||||
ClickActions actions,
|
CommandActions actions,
|
||||||
ClickActions leftClick,
|
CommandActions leftClick,
|
||||||
ClickActions rightClick,
|
CommandActions rightClick,
|
||||||
ClickActions shiftLeftClick,
|
CommandActions shiftLeftClick,
|
||||||
ClickActions shiftRightClick,
|
CommandActions shiftRightClick,
|
||||||
String damage,
|
String damage,
|
||||||
String itemModel,
|
String itemModel,
|
||||||
String customModelData,
|
String customModelData,
|
||||||
@ -42,11 +42,11 @@ public record PanelItem(
|
|||||||
String tooltip,
|
String tooltip,
|
||||||
String animate,
|
String animate,
|
||||||
String conditions,
|
String conditions,
|
||||||
ClickActions actions,
|
CommandActions actions,
|
||||||
ClickActions leftClick,
|
CommandActions leftClick,
|
||||||
ClickActions rightClick,
|
CommandActions rightClick,
|
||||||
ClickActions shiftLeftClick,
|
CommandActions shiftLeftClick,
|
||||||
ClickActions shiftRightClick,
|
CommandActions shiftRightClick,
|
||||||
String damage,
|
String damage,
|
||||||
String itemModel,
|
String itemModel,
|
||||||
String customModelData,
|
String customModelData,
|
||||||
@ -94,11 +94,11 @@ public record PanelItem(
|
|||||||
String animate = section.getString("animate", "");
|
String animate = section.getString("animate", "");
|
||||||
String conditions = section.getString("conditions", "");
|
String conditions = section.getString("conditions", "");
|
||||||
|
|
||||||
ClickActions actions = ClickActions.fromSection(section.getConfigurationSection("actions"));
|
CommandActions actions = CommandActions.fromSection(section.getConfigurationSection("actions"));
|
||||||
ClickActions leftClick = ClickActions.fromSection(section.getConfigurationSection("left-click"));
|
CommandActions leftClick = CommandActions.fromSection(section.getConfigurationSection("left-click"));
|
||||||
ClickActions rightClick = ClickActions.fromSection(section.getConfigurationSection("right-click"));
|
CommandActions rightClick = CommandActions.fromSection(section.getConfigurationSection("right-click"));
|
||||||
ClickActions shiftLeftClick = ClickActions.fromSection(section.getConfigurationSection("shift-left-click"));
|
CommandActions shiftLeftClick = CommandActions.fromSection(section.getConfigurationSection("shift-left-click"));
|
||||||
ClickActions shiftRightClick = ClickActions.fromSection(section.getConfigurationSection("shift-right-click"));
|
CommandActions shiftRightClick = CommandActions.fromSection(section.getConfigurationSection("shift-right-click"));
|
||||||
|
|
||||||
String damage = section.getString("damage", "0");
|
String damage = section.getString("damage", "0");
|
||||||
String itemModel = section.getString("item-model", null);
|
String itemModel = section.getString("item-model", null);
|
||||||
@ -140,7 +140,7 @@ public record PanelItem(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickActions getClickActions(ClickType clickType) {
|
public CommandActions getClickActions(ClickType clickType) {
|
||||||
if(!actions.requirements().isEmpty() || !actions.commands().isEmpty()) return actions;
|
if(!actions.requirements().isEmpty() || !actions.commands().isEmpty()) return actions;
|
||||||
// LEFT case defaults
|
// LEFT case defaults
|
||||||
return switch (clickType) {
|
return switch (clickType) {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package me.rockyhawk.commandpanels.session.inventory.listeners;
|
|||||||
import me.rockyhawk.commandpanels.Context;
|
import me.rockyhawk.commandpanels.Context;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
import me.rockyhawk.commandpanels.session.ClickActions;
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.inventory.InventoryPanel;
|
import me.rockyhawk.commandpanels.session.inventory.InventoryPanel;
|
||||||
import me.rockyhawk.commandpanels.session.inventory.PanelItem;
|
import me.rockyhawk.commandpanels.session.inventory.PanelItem;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@ -53,7 +53,7 @@ public class ClickEvents implements Listener {
|
|||||||
if (!(player.getOpenInventory().getTopInventory().getHolder() instanceof InventoryPanel panel)) return;
|
if (!(player.getOpenInventory().getTopInventory().getHolder() instanceof InventoryPanel panel)) return;
|
||||||
|
|
||||||
// Run outside command actions
|
// Run outside command actions
|
||||||
ClickActions actions = panel.getOutsideCommands();
|
CommandActions actions = panel.getOutsideCommands();
|
||||||
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
||||||
commands.runCommands(panel, player, actions.fail());
|
commands.runCommands(panel, player, actions.fail());
|
||||||
return;
|
return;
|
||||||
@ -96,7 +96,7 @@ public class ClickEvents implements Listener {
|
|||||||
switch (e.getClick()) {
|
switch (e.getClick()) {
|
||||||
case LEFT, RIGHT, SHIFT_LEFT, SHIFT_RIGHT -> {
|
case LEFT, RIGHT, SHIFT_LEFT, SHIFT_RIGHT -> {
|
||||||
PanelItem panelItem = panel.getItems().get(itemId);
|
PanelItem panelItem = panel.getItems().get(itemId);
|
||||||
ClickActions actions = panelItem.getClickActions(e.getClick());
|
CommandActions actions = panelItem.getClickActions(e.getClick());
|
||||||
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
||||||
commands.runCommands(panel, player, actions.fail());
|
commands.runCommands(panel, player, actions.fail());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
package me.rockyhawk.commandpanels.session.inventory.listeners;
|
package me.rockyhawk.commandpanels.session.inventory.listeners;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.Context;
|
import me.rockyhawk.commandpanels.Context;
|
||||||
|
import me.rockyhawk.commandpanels.interaction.commands.CommandRunner;
|
||||||
|
import me.rockyhawk.commandpanels.interaction.commands.RequirementRunner;
|
||||||
|
import me.rockyhawk.commandpanels.session.CommandActions;
|
||||||
import me.rockyhawk.commandpanels.session.inventory.InventoryPanel;
|
import me.rockyhawk.commandpanels.session.inventory.InventoryPanel;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,9 +36,19 @@ public class InventoryEvents implements Listener {
|
|||||||
if (!(event.getPlayer() instanceof Player player)) return;
|
if (!(event.getPlayer() instanceof Player player)) return;
|
||||||
|
|
||||||
// Only remove the session if the player has one
|
// Only remove the session if the player has one
|
||||||
if (event.getInventory().getHolder() instanceof InventoryPanel) {
|
if (event.getInventory().getHolder() instanceof InventoryPanel panel) {
|
||||||
itemSanitiser(player.getInventory());
|
itemSanitiser(player.getInventory());
|
||||||
itemDropper(player, event.getInventory());
|
itemDropper(player, event.getInventory());
|
||||||
|
|
||||||
|
// Run close commands
|
||||||
|
RequirementRunner requirements = new RequirementRunner(ctx);
|
||||||
|
CommandRunner commands = new CommandRunner(ctx);
|
||||||
|
CommandActions actions = panel.getCloseCommands();
|
||||||
|
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
||||||
|
commands.runCommands(panel, player, actions.fail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands.runCommands(panel, player, actions.commands());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user