mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
added inventory lock and remove middle click
This commit is contained in:
parent
e2f2be8e8a
commit
27c526836b
@ -5,7 +5,6 @@ import me.rockyhawk.commandpanels.interaction.commands.CommandTagResolver;
|
||||
import me.rockyhawk.commandpanels.session.Panel;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class SessionTag implements CommandTagResolver {
|
||||
|
||||
@ -25,6 +25,7 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
||||
private final Map<String, List<String>> slots = new HashMap<>();
|
||||
private final ClickActions outside;
|
||||
private final String floodgate;
|
||||
private final String inventoryLock;
|
||||
private final String updateDelay;
|
||||
|
||||
public InventoryPanel(String name, YamlConfiguration config) {
|
||||
@ -33,6 +34,7 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
||||
this.rows = config.getString("rows", "1");
|
||||
this.floodgate = config.getString("floodgate", "");
|
||||
this.updateDelay = config.getString("update-delay", "20");
|
||||
this.inventoryLock = config.getString("inventory-lock", "false");
|
||||
|
||||
outside = new ClickActions(
|
||||
config.getStringList("outside.requirements"),
|
||||
@ -116,6 +118,10 @@ public class InventoryPanel extends Panel implements InventoryHolder {
|
||||
return outside;
|
||||
}
|
||||
|
||||
public String getInventoryLock() {
|
||||
return inventoryLock;
|
||||
}
|
||||
|
||||
// For InventoryHolder implementation
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
|
||||
@ -19,7 +19,6 @@ public record PanelItem(
|
||||
ClickActions actions,
|
||||
ClickActions leftClick,
|
||||
ClickActions rightClick,
|
||||
ClickActions middleClick,
|
||||
ClickActions shiftLeftClick,
|
||||
ClickActions shiftRightClick,
|
||||
String damage,
|
||||
@ -46,7 +45,6 @@ public record PanelItem(
|
||||
ClickActions actions,
|
||||
ClickActions leftClick,
|
||||
ClickActions rightClick,
|
||||
ClickActions middleClick,
|
||||
ClickActions shiftLeftClick,
|
||||
ClickActions shiftRightClick,
|
||||
String damage,
|
||||
@ -72,7 +70,6 @@ public record PanelItem(
|
||||
this.actions = actions;
|
||||
this.leftClick = leftClick;
|
||||
this.rightClick = rightClick;
|
||||
this.middleClick = middleClick;
|
||||
this.shiftLeftClick = shiftLeftClick;
|
||||
this.shiftRightClick = shiftRightClick;
|
||||
this.damage = damage;
|
||||
@ -100,7 +97,6 @@ public record PanelItem(
|
||||
ClickActions actions = ClickActions.fromSection(section.getConfigurationSection("actions"));
|
||||
ClickActions leftClick = ClickActions.fromSection(section.getConfigurationSection("left-click"));
|
||||
ClickActions rightClick = ClickActions.fromSection(section.getConfigurationSection("right-click"));
|
||||
ClickActions middleClick = ClickActions.fromSection(section.getConfigurationSection("middle-click"));
|
||||
ClickActions shiftLeftClick = ClickActions.fromSection(section.getConfigurationSection("shift-left-click"));
|
||||
ClickActions shiftRightClick = ClickActions.fromSection(section.getConfigurationSection("shift-right-click"));
|
||||
|
||||
@ -129,7 +125,6 @@ public record PanelItem(
|
||||
actions,
|
||||
leftClick,
|
||||
rightClick,
|
||||
middleClick,
|
||||
shiftLeftClick,
|
||||
shiftRightClick,
|
||||
damage,
|
||||
@ -150,7 +145,6 @@ public record PanelItem(
|
||||
// LEFT case defaults
|
||||
return switch (clickType) {
|
||||
case RIGHT -> rightClick;
|
||||
case MIDDLE -> middleClick;
|
||||
case SHIFT_LEFT -> shiftLeftClick;
|
||||
case SHIFT_RIGHT -> shiftRightClick;
|
||||
default -> leftClick;
|
||||
|
||||
@ -31,12 +31,28 @@ public class ClickEvents implements Listener {
|
||||
requirements = new RequirementRunner(ctx);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInventoryClick(InventoryClickEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player player)) return;
|
||||
if (e.getClickedInventory() == null) return;
|
||||
if (!(player.getOpenInventory().getTopInventory().getHolder() instanceof InventoryPanel panel)) return;
|
||||
if (e.getClickedInventory() != e.getView().getBottomInventory()) return;
|
||||
|
||||
// Cancel player inventory click if locked
|
||||
if (e.getClickedInventory() != null) {
|
||||
boolean isLocked = Boolean.parseBoolean(
|
||||
ctx.text.parseTextToString(player,panel.getInventoryLock()));
|
||||
if(isLocked) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
// Run outside command actions
|
||||
ClickActions actions = panel.getOutsideCommands();
|
||||
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
||||
commands.runCommands(panel, player, actions.fail());
|
||||
@ -78,7 +94,7 @@ public class ClickEvents implements Listener {
|
||||
|
||||
// Check valid interaction types
|
||||
switch (e.getClick()) {
|
||||
case LEFT, RIGHT, MIDDLE, SHIFT_LEFT, SHIFT_RIGHT -> {
|
||||
case LEFT, RIGHT, SHIFT_LEFT, SHIFT_RIGHT -> {
|
||||
PanelItem panelItem = panel.getItems().get(itemId);
|
||||
ClickActions actions = panelItem.getClickActions(e.getClick());
|
||||
if(!requirements.processRequirements(panel, player, actions.requirements())){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user