diff --git a/resource/plugin.yml b/resource/plugin.yml index 71bfe13..5ae8a6c 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.12.6 +version: 3.13.0 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandpanels/CommandPanels.java b/src/me/rockyhawk/commandpanels/CommandPanels.java index 6be3960..027ae33 100644 --- a/src/me/rockyhawk/commandpanels/CommandPanels.java +++ b/src/me/rockyhawk/commandpanels/CommandPanels.java @@ -14,6 +14,7 @@ import me.realized.tokenmanager.api.TokenManager; import me.rockyhawk.commandpanels.classresources.*; import me.rockyhawk.commandpanels.commands.*; import me.rockyhawk.commandpanels.completetabs.CpTabComplete; +import me.rockyhawk.commandpanels.customcommands.CommandPlaceholderLoader; import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom; import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate; import me.rockyhawk.commandpanels.generatepanels.GenUtils; @@ -75,6 +76,7 @@ public class CommandPanels extends JavaPlugin { public LegacyVersion legacy = new LegacyVersion(this); public OpenPanelsLoader openPanels = new OpenPanelsLoader(this); public OpenGUI createGUI = new OpenGUI(this); + public CommandPlaceholderLoader customCommand = new CommandPlaceholderLoader(this); public File panelsf; public YamlConfiguration blockConfig; //where panel block locations are stored @@ -361,6 +363,15 @@ public class CommandPanels extends JavaPlugin { str = str.replace(str.substring(start, end) + "%", papi(p, "false")); } } + + for(String[] placeholder : customCommand.getCCP(p.getName())){ + while (str.contains(placeholder[0])) { + int start = str.indexOf(placeholder[0]); + int end = start+placeholder[0].length()-1; + str = str.replace(str.substring(start, end) + "%", placeholder[1]); + } + } + //does %cp-random-MIN,MAX% while (str.contains("%cp-random-")) { int start = str.indexOf("%cp-random-"); @@ -381,6 +392,7 @@ public class CommandPanels extends JavaPlugin { str = str.replace(str.substring(start, end) + "-find%", playerFind[Integer.parseInt(playerLocation) - 1].getName()); } } + try { if (econ != null) { str = str.replaceAll("%cp-player-balance%", String.valueOf(Math.round(econ.getBalance(p)))); diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java index 4815d39..c0eec09 100644 --- a/src/me/rockyhawk/commandpanels/Utils.java +++ b/src/me/rockyhawk/commandpanels/Utils.java @@ -1,17 +1,13 @@ package me.rockyhawk.commandpanels; -import org.bukkit.*; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; -import java.io.File; import java.util.*; public class Utils implements Listener { @@ -51,7 +47,6 @@ public class Utils implements Listener { o=o-1; } } - redirectPanel(p,cf,section,e.getSlot()); if(cf.contains("item." + e.getSlot() + section + ".commands")) { List commands = cf.getStringList("item." + e.getSlot() + section + ".commands"); if (commands.size() != 0) { @@ -122,44 +117,4 @@ public class Utils implements Listener { } } } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e){ - Player p = e.getPlayer(); - if(p.isOp() || p.hasPermission("*.*")){ - if(plugin.update) { - p.sendMessage(ChatColor.WHITE + "CommandPanels " + ChatColor.DARK_RED + "is not running the latest version! A new version is available at"); - p.sendMessage(ChatColor.RED + "https://www.spigotmc.org/resources/command-panels-custom-guis.67788/"); - } - } - } - - public void redirectPanel(Player p, ConfigurationSection cf, String section, int slot){ - String tag = plugin.config.getString("config.format.tag") + " "; - if(!cf.contains("item." + slot + section + ".redirect") || !cf.contains("item." + slot + section + ".redirect.panel")) { - return; - } - String panelName = cf.getString("item." + slot + section + ".redirect.panel"); - ConfigurationSection panelConfig = null; - for(String[] tempName : plugin.panelNames){ - if(tempName[0].equals(panelName)){ - panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))).getConfigurationSection("panels." + panelName); - break; - } - } - if(panelConfig == null){ - p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel"))); - return; - } - if(cf.contains("item." + slot + section + ".redirect.replacements")){ - if(!panelConfig.getString("panels." + panelName + ".panelType").equalsIgnoreCase("temporary") && plugin.config.getBoolean("config.refresh-panels")){ - p.sendMessage(plugin.papi(tag + ChatColor.RED + panelName + " panel type needs to be temporary to replace elements.")); - } - for(String sectionName : cf.getConfigurationSection("item." + slot + section + ".redirect.replacements").getKeys(false)){ - ConfigurationSection temp = cf.getConfigurationSection("item." + slot + section + ".redirect.replacements." + sectionName); - panelConfig.set("panels." + panelName + ".item." + sectionName, temp); - } - } - plugin.openVoids.openCommandPanel(p, p, panelName, panelConfig, false); - } } diff --git a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java index 6b9bfb7..088d8bb 100644 --- a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java @@ -35,8 +35,14 @@ public class CommandTags { assert player != null; player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } else if (command.split("\\s")[0].equalsIgnoreCase("open=")) { - //if player uses open= it will open the panel forced - String panelName = command.split("\\s")[1]; + //if player uses open= it will open the panel, with the option to add custom placeholders + String[] cmd = command.split("\\s"); + String panelName = cmd[1]; + for(int i = 2; i < cmd.length; i++){ + if(cmd[i].startsWith("%cp-")){ + plugin.customCommand.addCCP(panelName,p.getName(),cmd[i].split(":")[0],cmd[i].split(":")[1]); + } + } for(String[] tempName : plugin.panelNames){ if(tempName[0].equals(panelName)){ ConfigurationSection panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))).getConfigurationSection("panels." + panelName); diff --git a/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java b/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java index a9f37a1..911918b 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java +++ b/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java @@ -20,6 +20,10 @@ public class ExecuteOpenVoids { //this is the main method to open a panel public void openCommandPanel(CommandSender sender, Player p, String panelName, ConfigurationSection cf, boolean sendOpenedMessage){ String tag = plugin.config.getString("config.format.tag") + " "; + if(p.isSleeping()){ + //avoid plugin glitches when sleeping + return; + } if (sender.hasPermission("commandpanel.panel." + cf.getString("perm"))) { //if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person if(sender.hasPermission("commandpanel.other") || !sendOpenedMessage) { diff --git a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java index 5041282..50a9a07 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java +++ b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java @@ -35,9 +35,9 @@ public class ItemCreation { @SuppressWarnings("deprecation") public ItemStack makeItemFromConfig(ConfigurationSection itemSection, Player p, boolean placeholders, boolean colours){ String tag = plugin.config.getString("config.format.tag") + " "; - String material = itemSection.getString("material"); + String material = plugin.papiNoColour(p,itemSection.getString("material")); try { - if (Objects.requireNonNull(itemSection.getString("material")).equalsIgnoreCase("AIR")) { + if (Objects.requireNonNull(material).equalsIgnoreCase("AIR")) { return null; } }catch(NullPointerException e){ @@ -50,7 +50,6 @@ public class ItemCreation { String matskull; String skullname; //this will convert the %cp-player-online-1-find% into cps= NAME - assert material != null; if (material.contains("%cp-player-online-")) { int start = material.indexOf("%cp-player-online-"); int end = material.lastIndexOf("-find%"); @@ -340,8 +339,8 @@ public class ItemCreation { //if output is true, and values match it will be this item, vice versa outputValue = cf.getBoolean("hasgreater.output"); } - int value = Integer.parseInt(ChatColor.stripColor(plugin.papi(p,plugin.setCpPlaceholders(p,cf.getString("hasgreater.value"))))); - double compare = Double.parseDouble(ChatColor.stripColor(plugin.papi(p,plugin.setCpPlaceholders(p,cf.getString("hasgreater.compare"))))); + double value = Double.parseDouble(ChatColor.stripColor(plugin.papiNoColour(p,cf.getString("hasgreater.value")))); + double compare = Double.parseDouble(ChatColor.stripColor(plugin.papiNoColour(p,cf.getString("hasgreater.compare")))); if ((compare >= value) == outputValue) { //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasgreater")), p); @@ -356,8 +355,8 @@ public class ItemCreation { //if output is true, and values match it will be this item, vice versa outputValue = cf.getBoolean("hasgreater" + count + ".output"); } - value = Integer.parseInt(ChatColor.stripColor(plugin.papi(p,plugin.setCpPlaceholders(p,cf.getString("hasgreater" + count + ".value"))))); - compare = Double.parseDouble(ChatColor.stripColor(plugin.papi(p,plugin.setCpPlaceholders(p,cf.getString("hasgreater" + count + ".compare"))))); + value = Double.parseDouble(ChatColor.stripColor(plugin.papiNoColour(p,cf.getString("hasgreater" + count + ".value")))); + compare = Double.parseDouble(ChatColor.stripColor(plugin.papiNoColour(p,cf.getString("hasgreater" + count + ".compare")))); if ((compare >= value) == outputValue) { //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasgreater" + count)), p); diff --git a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java b/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java index ea99577..d333f8c 100644 --- a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java +++ b/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java @@ -388,6 +388,22 @@ public class OpenEditorGuis { plugin.setName(temp, ChatColor.WHITE + "Item Potion Effect", lore, p,true, true); i.setItem(7, temp); + temp = new ItemStack(Material.PAPER, 1); + lore.clear(); + lore.add(ChatColor.GRAY + "Duplicate item visuals in other slots"); + lore.add(ChatColor.GRAY + "- Left click to add duplicate item/s"); + lore.add(ChatColor.GRAY + "- Right click to remove duplicate item/s"); + if (cf.contains("duplicate")) { + lore.add(ChatColor.WHITE + "-----------------------------"); + int count = 1; + for (String tempLore : cf.getString("duplicate").split(",")) { + lore.add(ChatColor.WHITE + Integer.toString(count) + ") " + tempLore); + count += 1; + } + } + plugin.setName(temp, ChatColor.WHITE + "Item Duplicates", lore, p, true, true); + i.setItem(13, temp); + temp = new ItemStack(Material.FEATHER, 1); lore.clear(); lore.add(ChatColor.GRAY + "Display a lore under the item name"); diff --git a/src/me/rockyhawk/commandpanels/customcommands/CommandPlaceholderLoader.java b/src/me/rockyhawk/commandpanels/customcommands/CommandPlaceholderLoader.java new file mode 100644 index 0000000..c155a65 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/customcommands/CommandPlaceholderLoader.java @@ -0,0 +1,39 @@ +package me.rockyhawk.commandpanels.customcommands; + +import me.rockyhawk.commandpanels.CommandPanels; +import java.util.ArrayList; + +public class CommandPlaceholderLoader { + CommandPanels plugin; + public CommandPlaceholderLoader(CommandPanels pl) { + this.plugin = pl; + } + + ArrayList pendingPlaceholders = new ArrayList<>(); //should read: panelName, playerName, placeholder, argument + + //this will be used with the cpPlaceholder void, when the panel is closed it will remove the placeholder + public void addCCP(String panelName, String playerName, String placeholder, String argument){ + pendingPlaceholders.add(new String[]{panelName,playerName,placeholder,argument}); + } + + //will remove all pending placeholders for a certain player & panel + public void removeCCP(String panelName, String playerName){ + for(int i = 0; i < pendingPlaceholders.size(); i++){ + if(playerName.equals(pendingPlaceholders.get(i)[1]) && panelName.equals(pendingPlaceholders.get(i)[0])){ + pendingPlaceholders.remove(i); + i--; + } + } + } + + //will return placeholder,argument + public ArrayList getCCP(String playerName){ + ArrayList returnPlaceholders = new ArrayList<>(); + for(String[] temp : pendingPlaceholders){ + if(temp[1].equals(playerName)){ + returnPlaceholders.add(new String[]{temp[2],temp[3]}); + } + } + return returnPlaceholders; + } +} diff --git a/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java b/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java index c5afb81..17de290 100644 --- a/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java +++ b/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java @@ -1,7 +1,6 @@ package me.rockyhawk.commandpanels.customcommands; import me.rockyhawk.commandpanels.CommandPanels; -import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.EventHandler; @@ -32,21 +31,37 @@ public class Commandpanelcustom implements Listener { tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]); if (tempFile.contains("commands")) { List panelCommands = tempFile.getStringList("commands"); - if (panelCommands.contains(e.getMessage().replace("/", ""))) { - e.setCancelled(true); - plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); - return; - } - } + for(String cmd : panelCommands){ + if(cmd.equalsIgnoreCase(e.getMessage().replace("/", ""))){ + e.setCancelled(true); + plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); + return; + } - //this will be deleted in 3.13.x - if (tempFile.contains("command")) { - List panelCommands = Arrays.asList(tempFile.getString("command").split("\\s")); - if (panelCommands.contains(e.getMessage().replace("/", ""))) { - e.setCancelled(true); - plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "[CommandPanels] Using command: for custom commands will soon be deprecated. Please use commands: as shown in the wiki instead!"); - plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); - return; + boolean correctCommand = true; + ArrayList placeholders = new ArrayList<>(); //should read placeholder,argument + String[] args = cmd.split("\\s"); + String[] executedCommand = e.getMessage().replace("/", "").split("\\s"); //command split into args + if(args.length != executedCommand.length){ + continue; + } + + for(int i = 0; i < cmd.split("\\s").length; i++){ + if(args[i].startsWith("%cp-")){ + placeholders.add(new String[]{args[i], executedCommand[i]}); + }else if(!args[i].equals(executedCommand[i])){ + correctCommand = false; + } + } + + if(correctCommand){ + e.setCancelled(true); + for(String[] placeholder : placeholders){ + plugin.customCommand.addCCP(panelName[0],e.getPlayer().getName(),placeholder[0],placeholder[1]); + } + plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); + return; + } } } } diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java index 84efb18..9430aeb 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java @@ -13,6 +13,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -518,6 +519,7 @@ public class EditorUserInput implements Listener { commandsOnOpenRemove.remove(Integer.parseInt(e.getMessage())-1); }catch (Exception ex){ p.sendMessage(plugin.papi( tag + ChatColor.RED + "Could not find command!")); + plugin.debug(ex); break; } if(commandsOnOpenRemove.size() == 0){ @@ -550,6 +552,7 @@ public class EditorUserInput implements Listener { loreOnOpenRemove.remove(Integer.parseInt(e.getMessage())-1); }catch (Exception ex){ p.sendMessage(plugin.papi( tag + ChatColor.RED + "Could not find lore!")); + plugin.debug(ex); break; } if(loreOnOpenRemove.size() == 0){ @@ -560,6 +563,46 @@ public class EditorUserInput implements Listener { savePanelFile(cf, cfile, panelName, panelFile); p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed lore line " + e.getMessage())); break; + case "duplicate:add": + if(cf.contains("item." + itemSlot + ".duplicate")){ + cf.set("item." + itemSlot + ".duplicate", cf.getString("item." + itemSlot + ".duplicate") + "," + e.getMessage()); + }else{ + cf.set("item." + itemSlot + ".duplicate", e.getMessage()); + } + savePanelFile(cf, cfile, panelName, panelFile); + p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new duplicate item/s: " + e.getMessage())); + break; + case "duplicate:remove": + if(cf.contains("item." + itemSlot + ".duplicate")){ + if(cf.getString("item." + itemSlot + ".duplicate").contains(",")) { + try { + String[] duplicateItems = cf.getString("item." + itemSlot + ".duplicate").split(","); + StringBuilder items = new StringBuilder(); + for(int s = 0; s < duplicateItems.length; s++){ + if(Integer.parseInt(e.getMessage()) != s+1) { + items.append(duplicateItems[s]); + items.append(","); + } + } + cf.set("item." + itemSlot + ".duplicate", items.toString()); + } catch (Exception ex) { + p.sendMessage(plugin.papi(tag + ChatColor.RED + "Could not delete or find item!")); + plugin.debug(ex); + break; + } + if(cf.getString("item." + itemSlot + ".duplicate").equals("")){ + cf.set("item." + itemSlot + ".duplicate", null); + } + }else{ + cf.set("item." + itemSlot + ".duplicate", null); + } + }else{ + p.sendMessage(plugin.papi( tag + ChatColor.RED + "No items found to remove!")); + break; + } + savePanelFile(cf, cfile, panelName, panelFile); + p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed duplicate item/s: " + e.getMessage())); + break; } } diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java index cec7d53..dd0fc8d 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java @@ -319,6 +319,7 @@ public class EditorUtils implements Listener { //this is put here to avoid conflicts, close panel if it is closed for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){ if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){ + plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName()); plugin.openPanels.openPanelsPN.remove(i); plugin.openPanels.openPanelsCF.remove(i); return; @@ -556,6 +557,17 @@ public class EditorUtils implements Listener { p.sendMessage(plugin.papi(tag + ChatColor.WHITE + "Enter New Item Potion Effect")); p.closeInventory(); } + if(e.getSlot() == 13){ + //adds abilities to add and remove items + if(e.getClick().isLeftClick()) { + plugin.editorInputStrings.add(new String[]{p.getName(), panelName, "item:" + itemSlot + ":duplicate:add"}); + p.sendMessage(plugin.papi(tag + ChatColor.WHITE + "Enter Duplicate Item Location/s")); + }else{ + plugin.editorInputStrings.add(new String[]{p.getName(), panelName, "item:" + itemSlot + ":duplicate:remove"}); + p.sendMessage(plugin.papi(tag + ChatColor.WHITE + "Enter Duplicate Item/s to Remove (must be an integer)")); + } + p.closeInventory(); + } if(e.getSlot() == 19){ //adds abilities to add and remove lines if(e.getClick().isLeftClick()) { diff --git a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java index 2d14409..6abefac 100644 --- a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java +++ b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java @@ -11,7 +11,6 @@ import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; -import java.util.Arrays; import java.util.Objects; public class Commandpanelrefresher implements Listener { diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java index 1668593..cfcef28 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java @@ -9,6 +9,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; import java.util.Iterator; import java.util.Objects; @@ -60,7 +61,40 @@ public class OpenGUI { } ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(pconfig.getConfigurationSection("item." + item.split("\\s")[c] + section)), p, onOpen != 3, onOpen != 3); try { + //place item into the GUI i.setItem(Integer.parseInt(item.split("\\s")[c]), s); + //only place duplicate items in without the editor mode. These are merely visual and will not carry over commands + if(pconfig.contains("item." + item.split("\\s")[c] + section + ".duplicate") && onOpen != 3) { + try { + String[] duplicateItems = pconfig.getString("item." + item.split("\\s")[c] + section + ".duplicate").split(","); + for (String tempDupe : duplicateItems) { + if (tempDupe.contains("-")) { + //if there is multiple dupe items, convert numbers to ints + int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])}; + for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){ + try{ + if(i.getItem(n).getType() == Material.AIR){ + i.setItem(n, s); + } + }catch(NullPointerException ignore){ + i.setItem(n, s); + } + } + } else { + //if there is only one dupe item + try{ + if(i.getItem(Integer.parseInt(tempDupe)).getType() == Material.AIR){ + i.setItem(Integer.parseInt(tempDupe), s); + } + }catch(NullPointerException ignore){ + i.setItem(Integer.parseInt(tempDupe), s); + } + } + } + }catch(NullPointerException nullp){ + plugin.debug(nullp); + } + } } catch (ArrayIndexOutOfBoundsException var24) { plugin.debug(var24); if (plugin.debug) { diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java index 1a2a421..c83117c 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java @@ -60,6 +60,7 @@ public class OpenPanelsLoader { return false; } + //tell loader that a panel has been opened public void openPanelForLoader(String playerName, String panelName, ConfigurationSection cf){ //just to make sure there are no duplicates for(int i = 0; i < openPanelsCF.size(); i++){ @@ -73,6 +74,7 @@ public class OpenPanelsLoader { openPanelsPN.add(new String[]{playerName,panelName}); } + //tell loader that the panel is closed public void closePanelForLoader(String playerName, String panelName){ for(int i = 0; i < openPanelsCF.size(); i++){ if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){ diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java index a159fc2..795985b 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java @@ -14,10 +14,12 @@ public class UtilsPanelsLoader implements Listener { this.plugin = pl; } + //tell panel loader that player has opened panel @EventHandler public void onPlayerClosePanel(PlayerQuitEvent e){ for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){ if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){ + plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName()); plugin.openPanels.openPanelsPN.remove(i); plugin.openPanels.openPanelsCF.remove(i); return; @@ -25,6 +27,7 @@ public class UtilsPanelsLoader implements Listener { } } + //tell panel loader that player has closed the panel @EventHandler public void onPlayerClosePanel(InventoryCloseEvent e){ //only do this if editor is disabled as it will disabled this code @@ -32,6 +35,7 @@ public class UtilsPanelsLoader implements Listener { //this is put here to avoid conflicts, close panel if it is closed for (int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++) { if (plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())) { + plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName()); plugin.openPanels.openPanelsPN.remove(i); plugin.openPanels.openPanelsCF.remove(i); return;