diff --git a/resource/config.yml b/resource/config.yml index 76c012b..db5a65d 100644 --- a/resource/config.yml +++ b/resource/config.yml @@ -48,6 +48,7 @@ placeholders: updater: auto-update: true minor-updates-only: true + update-checks: true purchase: currency: success: '&aSuccessfully Bought For $%cp-args%' diff --git a/resource/plugin.yml b/resource/plugin.yml index 8f8dc71..ea522e0 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.16.2.3 +version: 3.16.2.4 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java index d12f368..45bef32 100644 --- a/src/me/rockyhawk/commandpanels/Utils.java +++ b/src/me/rockyhawk/commandpanels/Utils.java @@ -35,7 +35,6 @@ public class Utils implements Listener { //when clicked on a panel Player p = (Player)e.getWhoClicked(); int clickedSlot = e.getSlot(); - ItemStack clicked = e.getCurrentItem(); if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top) || e.getClick() == ClickType.DOUBLE_CLICK){ return; @@ -52,7 +51,7 @@ public class Utils implements Listener { //if the panel is clicked on the outside area of the GUI if (panel.getConfig().contains("outside-commands")) { try { - plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands")); + plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick()); }catch(Exception s){ plugin.debug(s,p); } @@ -133,51 +132,12 @@ public class Utils implements Listener { } } commands = commandsAfterSequence; - for (int i = 0; commands.size() - 1 >= i; i++) { - try { - switch(commands.get(i).split("\\s")[0]){ - case "right=":{ - //if commands is for right clicking, remove the 'right=' and continue - commands.set(i, commands.get(i).replace("right=", "").trim()); - if (e.getClick() != ClickType.RIGHT) { - continue; - } - break; - } - case "rightshift=":{ - //if commands is for right clicking, remove the 'right=' and continue - commands.set(i, commands.get(i).replace("rightshift=", "").trim()); - if (e.getClick() != ClickType.SHIFT_RIGHT) { - continue; - } - break; - } - case "left=":{ - //if commands is for right clicking, remove the 'right=' and continue - commands.set(i, commands.get(i).replace("left=", "").trim()); - if (e.getClick() != ClickType.LEFT) { - continue; - } - break; - } - case "leftshift=":{ - //if commands is for right clicking, remove the 'right=' and continue - commands.set(i, commands.get(i).replace("leftshift=", "").trim()); - if (e.getClick() != ClickType.SHIFT_LEFT) { - continue; - } - break; - } - case "middle=":{ - commands.set(i, commands.get(i).replace("middle=", "").trim()); - if (e.getClick() != ClickType.MIDDLE) { - continue; - } - break; - } - } - } catch (Exception click) { - //skip if you can't do this + plugin.commandTags.runCommands(panel,position,p,commands,e.getClick()); + /*for (int i = 0; commands.size() - 1 >= i; i++) { + commands.set(i,plugin.commandTags.hasCorrectClick(commands.get(i),e.getClick())); + if(commands.get(i).equals("")){ + //click type is wrong + continue; } //start custom command placeholders try { @@ -198,7 +158,7 @@ public class Utils implements Listener { if(val == PaywallOutput.NotApplicable){ plugin.commandTags.runCommand(panel,position, p, commands.get(i)); } - } + }*/ } } } diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 2f9ac41..c702485 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -17,6 +17,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -30,6 +31,25 @@ public class CommandTags { this.plugin = pl; } + //with the click type included + public void runCommands(Panel panel, PanelPosition position,Player p, List commands, ClickType click){ + for (String command : commands) { + command = plugin.commandTags.hasCorrectClick(command,click); + if(command.equals("")){ + //click type is wrong + continue; + } + + PaywallOutput val = plugin.commandTags.commandPayWall(panel,p,command); + if(val == PaywallOutput.Blocked){ + break; + } + if(val == PaywallOutput.NotApplicable){ + plugin.commandTags.runCommand(panel,position,p, command); + } + } + } + public void runCommands(Panel panel, PanelPosition position,Player p, List commands){ for (String command : commands) { PaywallOutput val = plugin.commandTags.commandPayWall(panel,p,command); @@ -65,6 +85,56 @@ public class CommandTags { plugin.getServer().getPluginManager().registerEvents(new ItemTags(plugin), plugin); } + public String hasCorrectClick(String command, ClickType click){ + try { + switch(command.split("\\s")[0]){ + case "right=":{ + //if commands is for right clicking, remove the 'right=' and continue + command = command.replace("right= ", ""); + if (click != ClickType.RIGHT) { + return ""; + } + break; + } + case "rightshift=":{ + //if commands is for right clicking, remove the 'right=' and continue + command = command.replace("rightshift= ", ""); + if (click != ClickType.SHIFT_RIGHT) { + return ""; + } + break; + } + case "left=":{ + //if commands is for right clicking, remove the 'right=' and continue + command = command.replace("left= ", ""); + if (click != ClickType.LEFT) { + return ""; + } + break; + } + case "leftshift=":{ + //if commands is for right clicking, remove the 'right=' and continue + command = command.replace("leftshift= ", ""); + if (click != ClickType.SHIFT_LEFT) { + return ""; + } + break; + } + case "middle=":{ + command = command.replace("middle= ", ""); + if (click != ClickType.MIDDLE) { + return ""; + } + break; + } + } + return command; + } catch (Exception ex) { + return ""; + //skip if you can't do this + } + } + @SuppressWarnings("deprecation") public PaywallOutput commandPayWall(Panel panel, Player p, String command) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command String tag = plugin.config.getString("config.format.tag") + " "; diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/other/SpecialTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/other/SpecialTags.java index 96b7853..499a6c1 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/other/SpecialTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/other/SpecialTags.java @@ -24,7 +24,7 @@ public class SpecialTags implements Listener { e.commandTagUsed(); //if player uses open= it will open the panel, with the option to add custom placeholders String panelName = e.args[0]; - String cmd = String.join(" ",e.args).replace(e.args[0],"").trim(); + String cmd = String.join(" ",e.args).replace(e.args[0] + " ","").trim(); Panel openPanel = null; PanelPosition openPosition = e.pos; diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index e0f98f6..cb888cb 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -6,6 +6,7 @@ import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import java.util.HashMap; @@ -30,7 +31,7 @@ public class HotbarItemLoader { } //return true if found - public boolean stationaryExecute(int slot, Player p, boolean openPanel){ + public boolean stationaryExecute(int slot, Player p, ClickType click, boolean openPanel){ if(stationaryItems.get(p.getUniqueId()).list.containsKey(slot)){ if(openPanel) { try { @@ -49,9 +50,7 @@ public class HotbarItemLoader { return false; } if(panel.getHotbarSection(p).contains("commands")){ - for(String command : panel.getHotbarSection(p).getStringList("commands")){ - plugin.commandTags.runCommand(panel,PanelPosition.Top,p, command); - } + plugin.commandTags.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click); return true; } panel.open(p, PanelPosition.Top); diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java index e880782..9bc4f4f 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java @@ -14,6 +14,10 @@ public class UtilsChestSortEvent implements Listener { } @EventHandler public void onChestSortEvent(ChestSortEvent e){ + //if player is null it is not necessary + if(e.getPlayer() == null){ + return; + } //cancel if a panel is opened at all if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName(), PanelPosition.Top)){ e.setCancelled(true); diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java index caf4a00..2d8d001 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java @@ -40,7 +40,7 @@ public class UtilsOpenWithItem implements Listener { return; } if(e.getClickedInventory().getType() == InventoryType.PLAYER && !e.isCancelled()) { - if (plugin.hotbar.stationaryExecute(e.getSlot(), p, true)) { + if (plugin.hotbar.stationaryExecute(e.getSlot(), p,e.getClick(), true)) { e.setCancelled(true); p.updateInventory(); } diff --git a/src/me/rockyhawk/commandpanels/updater/Updater.java b/src/me/rockyhawk/commandpanels/updater/Updater.java index d8d62b2..faf1424 100644 --- a/src/me/rockyhawk/commandpanels/updater/Updater.java +++ b/src/me/rockyhawk/commandpanels/updater/Updater.java @@ -28,7 +28,7 @@ public class Updater implements Listener { //send update message when the player joins the game with the permission @EventHandler public void joinGame(PlayerJoinEvent e){ - if(e.getPlayer().hasPermission("commandpanel.update")){ + if(e.getPlayer().hasPermission("commandpanel.update") && plugin.config.getBoolean("updater.update-checks")){ if(githubNewUpdate(false)){ new BukkitRunnable() { @Override