diff --git a/resource/config.yml b/resource/config.yml index c565b29..dfe7e3e 100644 --- a/resource/config.yml +++ b/resource/config.yml @@ -1,6 +1,6 @@ # |------------------------------------------------------------------------ # | CommandPanels Config File -# | By RockyHawk v4.1 +# | By RockyHawk v4.2 # | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/ # |------------------------------------------------------------------------ config: diff --git a/resource/example.yml b/resource/example.yml index 5a518ab..c0e4dac 100644 --- a/resource/example.yml +++ b/resource/example.yml @@ -1,6 +1,6 @@ # |------------------------------------------------------------------------ # | CommandPanels Example File -# | By RockyHawk v2.0 +# | By RockyHawk v2.1 # | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/ # |------------------------------------------------------------------------ panels: @@ -99,7 +99,7 @@ panels: - '&fI will teleport you home!' commands: - home - - commandpanels:commandpanelclose + - cpc - console= title %cp-player-name% times 20 60 20 - console= title %cp-player-name% subtitle {"text":"%cp-player-displayname%","color":"green"} - console= title %cp-player-name% title {"text":"Welcome Home"} @@ -109,7 +109,7 @@ panels: potion: INSTANT_HEAL commands: - heal - - commandpanels:commandpanelclose + - cpc '34': material: REDSTONE_BLOCK name: '&cNo Permission' @@ -126,7 +126,7 @@ panels: - '&2to creative mode!' commands: - gamemode creative - - commandpanels:commandpanelclose + - cpc - console= title %cp-player-name% times 20 60 20 - console= title %cp-player-name% subtitle {"text":"You are now in creative mode!","color":"green"} - console= title %cp-player-name% title {"text":"Awesome %cp-player-displayname%"} diff --git a/resource/exampleLegacy.yml b/resource/exampleLegacy.yml index 3cdb0f6..6fe72dc 100644 --- a/resource/exampleLegacy.yml +++ b/resource/exampleLegacy.yml @@ -1,6 +1,6 @@ # |------------------------------------------------------------------------ -# | CommandPanels Classic Example File -# | By RockyHawk v2.0 +# | CommandPanels Legacy Example File +# | By RockyHawk v2.1 # | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/ # |------------------------------------------------------------------------ panels: @@ -101,7 +101,7 @@ panels: - '&fI will teleport you home!' commands: - home - - commandpanels:commandpanelclose + - cpc - console= title %cp-player-name% times 20 60 20 - console= title %cp-player-name% subtitle {"text":"%cp-player-displayname%","color":"green"} - console= title %cp-player-name% title {"text":"Welcome Home"} @@ -111,7 +111,7 @@ panels: name: '&5&lInstant Health II' commands: - heal - - commandpanels:commandpanelclose + - cpc '34': material: REDSTONE_BLOCK name: '&cNo Permission' @@ -128,7 +128,7 @@ panels: - '&2to creative mode!' commands: - gamemode creative - - commandpanels:commandpanelclose + - cpc - console= title %cp-player-name% times 20 60 20 - console= title %cp-player-name% subtitle {"text":"You are now in creative mode!","color":"green"} - console= title %cp-player-name% title {"text":"Awesome %cp-player-displayname%"} diff --git a/resource/plugin.yml b/resource/plugin.yml index 8c745ab..9e9cabb 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.14.2.2 +version: 3.14.2.3 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk @@ -22,10 +22,6 @@ commands: description: Add or remove panels from blocks being looked at. usage: /commandpanelblock aliases: [cpb, cpanelb] - commandpanelclose: - description: Close current GUI. - usage: /commandpanelclose - aliases: [cpc, cpanelc] commandpanelgenerate: description: Generate GUI. usage: /commandpanelgenerate diff --git a/src/me/rockyhawk/commandpanels/CommandPanels.java b/src/me/rockyhawk/commandpanels/CommandPanels.java index 82bf22d..6a55afe 100644 --- a/src/me/rockyhawk/commandpanels/CommandPanels.java +++ b/src/me/rockyhawk/commandpanels/CommandPanels.java @@ -127,7 +127,6 @@ public class CommandPanels extends JavaPlugin { Objects.requireNonNull(this.getCommand("commandpanelgenerate")).setExecutor(new Commandpanelsgenerate(this)); Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this)); Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this)); - Objects.requireNonNull(this.getCommand("commandpanelclose")).setExecutor(new Commandpanelclose(this)); Objects.requireNonNull(this.getCommand("commandpanelversion")).setExecutor(new Commandpanelversion(this)); Objects.requireNonNull(this.getCommand("commandpaneladdons")).setExecutor(new Commandpanelresources(this)); Objects.requireNonNull(this.getCommand("commandpanellist")).setExecutor(new Commandpanelslist(this)); @@ -561,7 +560,6 @@ public class CommandPanels extends JavaPlugin { if (p.hasPermission("commandpanel.addons")) { p.sendMessage(ChatColor.GOLD + "/cpa " + ChatColor.WHITE + "View downloadable panels for CommandPanels."); } - p.sendMessage(ChatColor.GOLD + "/cpc " + ChatColor.WHITE + "Close current GUI."); if (p.hasPermission("commandpanel.generate")) { p.sendMessage(ChatColor.GOLD + "/cpg " + ChatColor.WHITE + "Generate GUI from popup menu."); } @@ -569,7 +567,8 @@ public class CommandPanels extends JavaPlugin { p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version."); } if (p.hasPermission("commandpanel.update")) { - p.sendMessage(ChatColor.GOLD + "/cpv [version:latest:cancel]" + ChatColor.WHITE + "Download an update upon server reload/restart."); + p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart."); + p.sendMessage(ChatColor.GOLD + "/cpv [version:cancel] " + ChatColor.WHITE + "Download an update upon server reload/restart."); } if (p.hasPermission("commandpanel.edit")) { p.sendMessage(ChatColor.GOLD + "/cpe [panel] " + ChatColor.WHITE + "Edit a panel with the Panel Editor."); diff --git a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java index 739325b..1616596 100644 --- a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java @@ -24,427 +24,569 @@ public class CommandTags { @SuppressWarnings("deprecation") public void commandTags(Player p, String command, String commandRAW) { - //set cp placeholders, commandRAW is without placeholders - if (command.split("\\s")[0].equalsIgnoreCase("server=")) { - //this contacts bungee and tells it to send the server change command - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("Connect"); - out.writeUTF(command.split("\\s")[1]); - Player player = Bukkit.getPlayerExact(p.getName()); - 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, with the option to add custom placeholders - String panelName = commandRAW.split("\\s")[1]; - String cmd = commandRAW.replace("open= " + panelName,""); - panelName = plugin.papi(p,panelName); + //commandRAW is without placeholders + switch(command.split("\\s")[0]){ + case "server=":{ + //this contacts bungee and tells it to send the server change command + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Connect"); + out.writeUTF(command.split("\\s")[1]); + Player player = Bukkit.getPlayerExact(p.getName()); + assert player != null; + player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); + break; + } + case "cpc":{ + //this will close the current inventory + p.closeInventory(); + break; + } + case "open=":{ + //if player uses open= it will open the panel, with the option to add custom placeholders + String panelName = commandRAW.split("\\s")[1]; + String cmd = commandRAW.replace("open= " + panelName,""); + panelName = plugin.papi(p,panelName); - Character[] cm = ArrayUtils.toObject(cmd.toCharArray()); - for(int i = 0; i < cm.length; i++){ - if(cm[i].equals('[')){ - String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']')); - //do not change the placeholder - String placeholder = contents.substring(0,contents.indexOf(':')); - //only convert placeholders for the value - String value = plugin.papi(p,contents.substring(contents.indexOf(':')+1)); - plugin.customCommand.addCCP(panelName,p.getName(),placeholder,value); - i = i+contents.length()-1; + Character[] cm = ArrayUtils.toObject(cmd.toCharArray()); + for(int i = 0; i < cm.length; i++){ + if(cm[i].equals('[')){ + String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']')); + //do not change the placeholder + String placeholder = contents.substring(0,contents.indexOf(':')); + //only convert placeholders for the value + String value = plugin.papi(p,contents.substring(contents.indexOf(':')+1)); + plugin.customCommand.addCCP(panelName,p.getName(),placeholder,value); + i = i+contents.length()-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); - plugin.openPanels.skipPanels.add(p.getName()); - plugin.openVoids.openCommandPanel(p,p,panelName,panelConfig,false); - return; + 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); + if(plugin.openPanels.hasPanelOpen(p.getName())) { + plugin.openPanels.skipPanels.add(p.getName()); + } + plugin.openVoids.openCommandPanel(p,p,panelName,panelConfig,false); + return; + } } + break; } - }else if (command.split("\\s")[0].equalsIgnoreCase("placeholder=")) { - //if player uses placeholder= it will only change the placeholders for the panel - String panelName = commandRAW.split("\\s")[1]; - String cmd = commandRAW.replace("placeholder= " + panelName,""); - panelName = plugin.papi(p,panelName); + case "console=":{ + //if player uses console= it will perform command in the console + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("console=", "").trim()); + break; + } + case "placeholder=":{ + //if player uses placeholder= it will only change the placeholders for the panel + String panelName = commandRAW.split("\\s")[1]; + String cmd = commandRAW.replace("placeholder= " + panelName,""); + panelName = plugin.papi(p,panelName); - Character[] cm = ArrayUtils.toObject(cmd.toCharArray()); - for(int i = 0; i < cm.length; i++){ - if(cm[i].equals('[')){ - String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']')); - //do not change the placeholder - String placeholder = contents.substring(0,contents.indexOf(':')); - //only convert placeholders for the value - String value = plugin.papi(p,contents.substring(contents.indexOf(':')+1)); - plugin.customCommand.editCCP(panelName,p.getName(),placeholder,value); - i = i+contents.length()-1; - } - } - }else if (command.split("\\s")[0].equalsIgnoreCase("op=")) { - //if player uses op= it will perform command as op - boolean isop = p.isOp(); - try { - p.setOp(true); - Bukkit.dispatchCommand(p,command.replace("op=", "").trim()); - p.setOp(isop); - } catch (Exception exc) { - p.setOp(isop); - plugin.debug(exc); - p.sendMessage(plugin.tag + plugin.papi( plugin.config.getString("config.format.error") + " op=: Error in op command!")); - } - }else if (command.split("\\s")[0].equalsIgnoreCase("delay=")) { - //if player uses op= it will perform command as op - final int delaySeconds = Integer.parseInt(command.split("\\s")[1]); - String finalCommand = command.split("\\s",3)[2]; - new BukkitRunnable() { - @Override - public void run() { - commandTags(p, finalCommand, commandRAW); - this.cancel(); - } - }.runTaskTimer(plugin, 20*delaySeconds, 20); //20 ticks == 1 second - }else if (command.split("\\s")[0].equalsIgnoreCase("console=")) { - //if player uses console= it will perform command in the console - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("console=", "").trim()); - }else if (command.split("\\s")[0].equalsIgnoreCase("buy=")) { - //if player uses buy= it will be eg. buy= - try { - if (plugin.econ != null) { - if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { - plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()){ - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - //legacy ID - byte id = 0; - if(plugin.legacy.isLegacy()) { - for (String argsTemp : command.split("\\s")) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } - if (p.getInventory().firstEmpty() >= 0) { - p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); - } else { - Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney"))); + Character[] cm = ArrayUtils.toObject(cmd.toCharArray()); + for(int i = 0; i < cm.length; i++){ + if(cm[i].equals('[')){ + String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']')); + //do not change the placeholder + String placeholder = contents.substring(0,contents.indexOf(':')); + //only convert placeholders for the value + String value = plugin.papi(p,contents.substring(contents.indexOf(':')+1)); + plugin.customCommand.editCCP(panelName,p.getName(),placeholder,value); + i = i+contents.length()-1; } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); } - } catch (Exception buy) { - plugin.debug(buy); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + break; } - } else if (command.split("\\s")[0].equalsIgnoreCase("tokenbuy=")) { - //if player uses tokenbuy= it will be eg. tokenbuy= - try { - if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { - TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); - assert api != null; - int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); - if (balance >= Double.parseDouble(command.split("\\s")[1])) { - api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - //legacy ID - byte id = 0; - if(plugin.legacy.isLegacy()) { - for (String argsTemp : command.split("\\s")) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } - if (p.getInventory().firstEmpty() >= 0) { - p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); - } else { - Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token"))); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires TokenManager to work!")); - } - } catch (Exception buy) { - plugin.debug(buy); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("sell=")) { - //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] - try { - if (plugin.econ != null) { - boolean sold = false; - for (int f = 0; f < p.getInventory().getSize(); f++) { - ItemStack itm = p.getInventory().getItem(f); - if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) { - //determine if the command contains parameters for extensions - String potion = "false"; - for(String argsTemp : command.split("\\s")){ - if(argsTemp.startsWith("potion:")){ - potion = argsTemp.replace("potion:",""); - break; - } - } - //legacy ID - byte id = -1; - if(plugin.legacy.isLegacy()) { - for (String argsTemp : command.split("\\s")) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } - //check to ensure any extensions are checked - try { - if (!potion.equals("false")) { - PotionMeta potionMeta = (PotionMeta) itm.getItemMeta(); - assert potionMeta != null; - if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) { - continue; - } - } - if (id != -1) { - if (itm.getDurability() != id) { - continue; - } - } - }catch(Exception exc){ - //skip unless plugin.debug enabled - plugin.debug(exc); - } - if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) { - int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount(); - itm.setAmount(amt); - p.getInventory().setItem(f, amt > 0 ? itm : null); - plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1])); - sold = true; - p.updateInventory(); - break; - } - } - } - if (!sold) { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needitems"))); - } else { - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.sold")).isEmpty()) { - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Selling Requires Vault and an Economy to work!")); - } - } catch (Exception sell) { - plugin.debug(sell); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("tokensell=")) { - //if player uses tokensell= it will be eg. tokensell= [enchanted:KNOCKBACK:1] [potion:JUMP] - try { - if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { - TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); - boolean sold = false; - for (int f = 0; f < p.getInventory().getSize(); f++) { - ItemStack itm = p.getInventory().getItem(f); - if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) { - //determine if the command contains parameters for extensions - String potion = "false"; - for(String argsTemp : command.split("\\s")){ - if(argsTemp.startsWith("potion:")){ - potion = argsTemp.replace("potion:",""); - } - } - //legacy ID - byte id = -1; - if(plugin.legacy.isLegacy()) { - for (String argsTemp : command.split("\\s")) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } - //check to ensure any extensions are checked - try { - if (!potion.equals("false")) { - PotionMeta potionMeta = (PotionMeta) itm.getItemMeta(); - assert potionMeta != null; - if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect")); - return; - } - } - if (id != -1) { - if (itm.getDurability() != id) { - continue; - } - } - }catch(Exception exc){ - //skip if it cannot do unless plugin.debug is enabled - plugin.debug(exc); - } - if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) { - int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount(); - itm.setAmount(amt); - p.getInventory().setItem(f, amt > 0 ? itm : null); - plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1])); - assert api != null; - api.addTokens(p, Long.parseLong(command.split("\\s")[1])); - sold = true; - p.updateInventory(); - break; - } - } - } - if (!sold) { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needitems"))); - } else { - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).isEmpty()) { - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Selling Requires TokenManager to work!")); - } - } catch (Exception sell) { - plugin.debug(sell); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("msg=")) { - //if player uses msg= it will send the player a message - p.sendMessage(command.replace("msg=", "").trim()); - } else if (command.split("\\s")[0].equalsIgnoreCase("sound=")) { - //if player uses sound= it will play a sound (sound= [sound]) - try { - p.playSound(p.getLocation(), Sound.valueOf(command.split("\\s")[1]), 1F, 1F); - } catch (Exception s) { - plugin.debug(s); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("tokenbuycommand=")) { - //if player uses tokenbuycommand [price] [command] - try { - if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { - TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); - assert api != null; - int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); - if (balance >= Double.parseDouble(command.split("\\s")[1])) { - api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); - //execute command under here - String commandp = command; - commandp = commandp.replace("tokenbuycommand=", "").trim(); - String price = commandp.split(" ", 2)[0]; - commandp = commandp.split(" ", 2)[1]; - commandTags(p,commandp,commandRAW); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", price))); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token"))); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); - } - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("buycommand=")) { - //if player uses buycommand [price] [command] - try { - if (plugin.econ != null) { - if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { - plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); - //execute command under here - String commandp = command; - commandp = commandp.replace("buycommand=", "").trim(); - String price = commandp.split(" ", 2)[0]; - commandp = commandp.split(" ", 2)[1]; - commandTags(p,commandp,commandRAW); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) { - p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", price))); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney"))); - } - } else { - p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); - } - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - } - } else if (command.split("\\s")[0].equalsIgnoreCase("teleport=")) { - //if player uses teleport= x y z (optional other player) - if (command.split("\\s").length == 6) { - float x, y, z, yaw, pitch; //pitch is the heads Y axis and yaw is the X axis - x = Float.parseFloat(command.split("\\s")[1]); - y = Float.parseFloat(command.split("\\s")[2]); - z = Float.parseFloat(command.split("\\s")[3]); - yaw = Float.parseFloat(command.split("\\s")[4]); - pitch = Float.parseFloat(command.split("\\s")[5]); - p.teleport(new Location(p.getWorld(), x, y, z, yaw, pitch)); - } else if (command.split("\\s").length <= 4) { - float x, y, z; - x = Float.parseFloat(command.split("\\s")[1]); - y = Float.parseFloat(command.split("\\s")[2]); - z = Float.parseFloat(command.split("\\s")[3]); - p.teleport(new Location(p.getWorld(), x, y, z)); - } else { + case "op=":{ + //if player uses op= it will perform command as op + boolean isop = p.isOp(); try { - Player otherplayer = Bukkit.getPlayer(command.split("\\s")[4]); + p.setOp(true); + Bukkit.dispatchCommand(p,command.replace("op=", "").trim()); + p.setOp(isop); + } catch (Exception exc) { + p.setOp(isop); + plugin.debug(exc); + p.sendMessage(plugin.tag + plugin.papi( plugin.config.getString("config.format.error") + " op=: Error in op command!")); + } + break; + } + case "delay=":{ + //if player uses op= it will perform command as op + final int delaySeconds = Integer.parseInt(command.split("\\s")[1]); + String finalCommand = command.split("\\s",3)[2]; + new BukkitRunnable() { + @Override + public void run() { + commandTags(p, finalCommand, commandRAW); + this.cancel(); + } + }.runTaskTimer(plugin, 20*delaySeconds, 20); //20 ticks == 1 second + break; + } + case "buy=":{ + //if player uses buy= it will be eg. buy= + try { + if (plugin.econ != null) { + if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { + plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()){ + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + //legacy ID + byte id = 0; + if(plugin.legacy.isLegacy()) { + for (String argsTemp : command.split("\\s")) { + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + break; + } + } + } + if (p.getInventory().firstEmpty() >= 0) { + p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); + } else { + Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney"))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); + } + } catch (Exception buy) { + plugin.debug(buy); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "tokenbuy=":{ + //if player uses tokenbuy= it will be eg. tokenbuy= + try { + if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { + TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); + assert api != null; + int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); + if (balance >= Double.parseDouble(command.split("\\s")[1])) { + api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + //legacy ID + byte id = 0; + if(plugin.legacy.isLegacy()) { + for (String argsTemp : command.split("\\s")) { + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + break; + } + } + } + if (p.getInventory().firstEmpty() >= 0) { + p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); + } else { + Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id)); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token"))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires TokenManager to work!")); + } + } catch (Exception buy) { + plugin.debug(buy); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "sell=":{ + //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] + try { + if (plugin.econ != null) { + boolean sold = false; + for (int f = 0; f < p.getInventory().getSize(); f++) { + ItemStack itm = p.getInventory().getItem(f); + if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) { + //determine if the command contains parameters for extensions + String potion = "false"; + for(String argsTemp : command.split("\\s")){ + if(argsTemp.startsWith("potion:")){ + potion = argsTemp.replace("potion:",""); + break; + } + } + //legacy ID + byte id = -1; + if(plugin.legacy.isLegacy()) { + for (String argsTemp : command.split("\\s")) { + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + break; + } + } + } + //check to ensure any extensions are checked + try { + if (!potion.equals("false")) { + PotionMeta potionMeta = (PotionMeta) itm.getItemMeta(); + assert potionMeta != null; + if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) { + continue; + } + } + if (id != -1) { + if (itm.getDurability() != id) { + continue; + } + } + }catch(Exception exc){ + //skip unless plugin.debug enabled + plugin.debug(exc); + } + if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) { + int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount(); + itm.setAmount(amt); + p.getInventory().setItem(f, amt > 0 ? itm : null); + plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1])); + sold = true; + p.updateInventory(); + break; + } + } + } + if (!sold) { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needitems"))); + } else { + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.sold")).isEmpty()) { + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Selling Requires Vault and an Economy to work!")); + } + } catch (Exception sell) { + plugin.debug(sell); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "tokensell=":{ + //if player uses tokensell= it will be eg. tokensell= [enchanted:KNOCKBACK:1] [potion:JUMP] + try { + if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { + TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); + boolean sold = false; + for (int f = 0; f < p.getInventory().getSize(); f++) { + ItemStack itm = p.getInventory().getItem(f); + if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) { + //determine if the command contains parameters for extensions + String potion = "false"; + for(String argsTemp : command.split("\\s")){ + if(argsTemp.startsWith("potion:")){ + potion = argsTemp.replace("potion:",""); + } + } + //legacy ID + byte id = -1; + if(plugin.legacy.isLegacy()) { + for (String argsTemp : command.split("\\s")) { + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + break; + } + } + } + //check to ensure any extensions are checked + try { + if (!potion.equals("false")) { + PotionMeta potionMeta = (PotionMeta) itm.getItemMeta(); + assert potionMeta != null; + if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect")); + return; + } + } + if (id != -1) { + if (itm.getDurability() != id) { + continue; + } + } + }catch(Exception exc){ + //skip if it cannot do unless plugin.debug is enabled + plugin.debug(exc); + } + if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) { + int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount(); + itm.setAmount(amt); + p.getInventory().setItem(f, amt > 0 ? itm : null); + plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1])); + assert api != null; + api.addTokens(p, Long.parseLong(command.split("\\s")[1])); + sold = true; + p.updateInventory(); + break; + } + } + } + if (!sold) { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needitems"))); + } else { + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).isEmpty()) { + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Selling Requires TokenManager to work!")); + } + } catch (Exception sell) { + plugin.debug(sell); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "msg=":{ + //if player uses msg= it will send the player a message + p.sendMessage(command.replace("msg=", "").trim()); + break; + } + case "sound=":{ + //if player uses sound= it will play a sound (sound= [sound]) + try { + p.playSound(p.getLocation(), Sound.valueOf(command.split("\\s")[1]), 1F, 1F); + } catch (Exception s) { + plugin.debug(s); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "buycommand=":{ + //if player uses buycommand [price] [command] + try { + if (plugin.econ != null) { + if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { + plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); + //execute command under here + String commandp = command; + commandp = commandp.replace("buycommand=", "").trim(); + String price = commandp.split(" ", 2)[0]; + commandp = commandp.split(" ", 2)[1]; + commandTags(p,commandp,commandRAW); + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) { + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", price))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney"))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); + } + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "tokenbuycommand=":{ + //if player uses tokenbuycommand [price] [command] + try { + if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { + TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); + assert api != null; + int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); + if (balance >= Double.parseDouble(command.split("\\s")[1])) { + api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); + //execute command under here + String commandp = command; + commandp = commandp.replace("tokenbuycommand=", "").trim(); + String price = commandp.split(" ", 2)[0]; + commandp = commandp.split(" ", 2)[1]; + commandTags(p,commandp,commandRAW); + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { + p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", price))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token"))); + } + } else { + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!")); + } + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + case "teleport=":{ + //if player uses teleport= x y z (optional other player) + if (command.split("\\s").length == 6) { + float x, y, z, yaw, pitch; //pitch is the heads Y axis and yaw is the X axis + x = Float.parseFloat(command.split("\\s")[1]); + y = Float.parseFloat(command.split("\\s")[2]); + z = Float.parseFloat(command.split("\\s")[3]); + yaw = Float.parseFloat(command.split("\\s")[4]); + pitch = Float.parseFloat(command.split("\\s")[5]); + p.teleport(new Location(p.getWorld(), x, y, z, yaw, pitch)); + } else if (command.split("\\s").length <= 4) { float x, y, z; x = Float.parseFloat(command.split("\\s")[1]); y = Float.parseFloat(command.split("\\s")[2]); z = Float.parseFloat(command.split("\\s")[3]); - assert otherplayer != null; - otherplayer.teleport(new Location(otherplayer.getWorld(), x, y, z)); - } catch (Exception tpe) { - p.sendMessage(plugin.tag + plugin.config.getString("config.format.notitem")); + p.teleport(new Location(p.getWorld(), x, y, z)); + } else { + try { + Player otherplayer = Bukkit.getPlayer(command.split("\\s")[4]); + float x, y, z; + x = Float.parseFloat(command.split("\\s")[1]); + y = Float.parseFloat(command.split("\\s")[2]); + z = Float.parseFloat(command.split("\\s")[3]); + assert otherplayer != null; + otherplayer.teleport(new Location(otherplayer.getWorld(), x, y, z)); + } catch (Exception tpe) { + p.sendMessage(plugin.tag + plugin.config.getString("config.format.notitem")); + } } + break; } - } else if (command.split("\\s")[0].equalsIgnoreCase("stopsound=")) { - //if player uses stopsound= [sound] - try { - p.stopSound(Sound.valueOf(command.split("\\s")[1])); - } catch (Exception ss) { - plugin.debug(ss); - p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + case "sudo=":{ + //if player uses sudo= [command] to send a command as them + p.chat( "/" + command.replaceAll("sudo=", "").trim()); + break; } - }else if (command.split("\\s")[0].equalsIgnoreCase("send=")) { - //if player uses send= [message] to send a message as them - p.chat( command.replaceAll("send=", "").trim()); - }else if (command.split("\\s")[0].equalsIgnoreCase("sudo=")) { - //if player uses sudo= [command] to send a command as them - p.chat( "/" + command.replaceAll("sudo=", "").trim()); - } else { - Bukkit.dispatchCommand(p, command); + case "send=":{ + //if player uses send= [message] to send a message as them + p.chat( command.replaceAll("send=", "").trim()); + break; + } + case "stopsound=":{ + //if player uses stopsound= [sound] + try { + p.stopSound(Sound.valueOf(command.split("\\s")[1])); + } catch (Exception ss) { + plugin.debug(ss); + p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + } + break; + } + default: + Bukkit.dispatchCommand(p, command); } } @SuppressWarnings("deprecation") public int commandPayWall(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") + " "; - if (command.split("\\s")[0].equalsIgnoreCase("paywall=")) { - //if player uses paywall= [price] - try { - if (plugin.econ != null) { - if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { - plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); + switch(command.split("\\s")[0]){ + case "paywall=": { + //if player uses paywall= [price] + try { + if (plugin.econ != null) { + if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) { + plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1])); + //if the message is empty don't send + if(!plugin.config.getString("config.format.bought").isEmpty()) { + p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + return 1; + } else { + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney"))); + return 0; + } + } else { + p.sendMessage(plugin.papi( tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!")); + return 0; + } + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + return 0; + } + } + case "tokenpaywall=": { + //if player uses tokenpaywall= [price] + try { + if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { + TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); + assert api != null; + int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); + if (balance >= Double.parseDouble(command.split("\\s")[1])) { + api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); + //if the message is empty don't send + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { + p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); + } + return 1; + } else { + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney-token"))); + return 0; + } + } else { + p.sendMessage(plugin.papi( tag + ChatColor.RED + "Paying TokenManager to work!")); + return 0; + } + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + return 0; + } + } + case "item-paywall=": { + //if player uses item-paywall= [Material] [Amount] [Id] + try { + short id = 0; + if(command.split("\\s").length == 4){ + id = Short.parseShort(command.split("\\s")[3]); + } + ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])),Integer.parseInt(command.split("\\s")[2]), id); + int sellItemAmount = sellItem.getAmount(); + sellItem.setAmount(1); + int removedItem = 0; + for(ItemStack content : p.getInventory().getContents()){ + int contentAmount; + try { + contentAmount = content.getAmount(); + }catch(NullPointerException skip){ + //item is air + continue; + } + content.setAmount(1); + if(content.isSimilar(sellItem)){ + if(sellItemAmount <= contentAmount){ + content.setAmount(contentAmount-sellItemAmount); + p.updateInventory(); + removedItem = 1; + break; + } + } + content.setAmount(contentAmount); + } + if(removedItem == 0){ + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney"))); + }else{ + if(!Objects.requireNonNull(plugin.config.getString("config.format.sold")).isEmpty()) { + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.sold"))); + } + } + return removedItem; + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); + return 0; + } + } + case "xp-paywall=": { + //if player uses xp-paywall= [price] + try { + int balance = p.getLevel(); + if (balance >= Integer.parseInt(command.split("\\s")[1])) { + p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1])); //if the message is empty don't send - if(!plugin.config.getString("config.format.bought").isEmpty()) { + if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) { p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1]))); } return 1; @@ -452,107 +594,13 @@ public class CommandTags { p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney"))); return 0; } - } else { - p.sendMessage(plugin.papi( tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!")); + } catch (Exception buyc) { + plugin.debug(buyc); + p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); return 0; } - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - return 0; } - } else if (command.split("\\s")[0].equalsIgnoreCase("tokenpaywall=")) { - //if player uses tokenpaywall= [price] - try { - if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { - TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); - assert api != null; - int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0))); - if (balance >= Double.parseDouble(command.split("\\s")[1])) { - api.removeTokens(p, Long.parseLong(command.split("\\s")[1])); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) { - p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - return 1; - } else { - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney-token"))); - return 0; - } - } else { - p.sendMessage(plugin.papi( tag + ChatColor.RED + "Paying TokenManager to work!")); - return 0; - } - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - return 0; - } - }else if (command.split("\\s")[0].equalsIgnoreCase("item-paywall=")) { - //if player uses item-paywall= [Material] [Amount] [Id] - try { - short id = 0; - if(command.split("\\s").length == 4){ - id = Short.parseShort(command.split("\\s")[3]); - } - ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])),Integer.parseInt(command.split("\\s")[2]), id); - int sellItemAmount = sellItem.getAmount(); - sellItem.setAmount(1); - int removedItem = 0; - for(ItemStack content : p.getInventory().getContents()){ - int contentAmount; - try { - contentAmount = content.getAmount(); - }catch(NullPointerException skip){ - //item is air - continue; - } - content.setAmount(1); - if(content.isSimilar(sellItem)){ - if(sellItemAmount <= contentAmount){ - content.setAmount(contentAmount-sellItemAmount); - p.updateInventory(); - removedItem = 1; - break; - } - } - content.setAmount(contentAmount); - } - if(removedItem == 0){ - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney"))); - }else{ - if(!Objects.requireNonNull(plugin.config.getString("config.format.sold")).isEmpty()) { - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.sold"))); - } - } - return removedItem; - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - return 0; - } - }else if (command.split("\\s")[0].equalsIgnoreCase("xp-paywall=")) { - //if player uses xp-paywall= [price] - try { - int balance = p.getLevel(); - if (balance >= Integer.parseInt(command.split("\\s")[1])) { - p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1])); - //if the message is empty don't send - if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) { - p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1]))); - } - return 1; - } else { - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney"))); - return 0; - } - } catch (Exception buyc) { - plugin.debug(buyc); - p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command)); - return 0; - } - } else { - return 2; } + return 2; } } diff --git a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java b/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java index 472b8da..b043fdd 100644 --- a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java +++ b/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java @@ -325,11 +325,20 @@ public class OpenEditorGuis { temp = new ItemStack(Material.BOOK, 1); lore.clear(); - lore.add(ChatColor.GRAY + "- To refresh changes use"); - lore.add(ChatColor.GRAY + " /cp " + panelName + " item"); - lore.add(ChatColor.GRAY + "- Hotbar items will need a"); - lore.add(ChatColor.GRAY + " name to work properly."); - plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Tips", lore, p, true, true); + lore.add(ChatColor.GRAY + "Execute commands from Hotbar Item"); + lore.add(ChatColor.GRAY + "- Left click to add command"); + lore.add(ChatColor.GRAY + "- Right click to remove command"); + lore.add(ChatColor.GRAY + "If commands are added, the item will"); + lore.add(ChatColor.GRAY + "no longer automatically open the panel"); + if (cf.contains("open-with-item.commands")) { + lore.add(ChatColor.WHITE + "-------------------------------"); + int count = 1; + for (String tempLore : cf.getStringList("open-with-item.commands")) { + lore.add(ChatColor.WHITE + Integer.toString(count) + ") " + tempLore); + count += 1; + } + } + plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Commands", lore, p, true, true); i.setItem(44, temp); } diff --git a/src/me/rockyhawk/commandpanels/commands/Commandpanelclose.java b/src/me/rockyhawk/commandpanels/commands/Commandpanelclose.java deleted file mode 100644 index 5b083db..0000000 --- a/src/me/rockyhawk/commandpanels/commands/Commandpanelclose.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.rockyhawk.commandpanels.commands; - -import me.rockyhawk.commandpanels.CommandPanels; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -public class Commandpanelclose implements CommandExecutor { - CommandPanels plugin; - public Commandpanelclose(CommandPanels pl) { this.plugin = pl; } - - @EventHandler - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if(!(sender instanceof Player)) { - sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Please execute command as a Player!")); - return true; - } - Player p = (Player)sender; - - if (cmd.getName().equalsIgnoreCase("cpc") || cmd.getName().equalsIgnoreCase("commandpanelclose") && sender instanceof Player || cmd.getName().equalsIgnoreCase("cpanelc") && sender instanceof Player) { - p.closeInventory(); - return true; - } - p.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpc")); - return true; - } -} diff --git a/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java b/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java index 04bd224..3eb2232 100644 --- a/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java +++ b/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java @@ -28,6 +28,7 @@ public class Commandpanelsreload implements CommandExecutor { //empty } plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml")); + plugin.blockConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "blocks.yml")); //check for duplicates plugin.checkDuplicatePanel(sender); diff --git a/src/me/rockyhawk/commandpanels/commands/Commandpanelversion.java b/src/me/rockyhawk/commandpanels/commands/Commandpanelversion.java index 58e6bf0..95ee710 100644 --- a/src/me/rockyhawk/commandpanels/commands/Commandpanelversion.java +++ b/src/me/rockyhawk/commandpanels/commands/Commandpanelversion.java @@ -31,16 +31,16 @@ public class Commandpanelversion implements CommandExecutor { if (sender.hasPermission("commandpanel.update")) { if (args[0].equals("cancel")) { plugin.updater.downloadVersionManually = null; - sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Will not download a new version on reload or restart.")); + sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Will not download a new version on restart.")); } else { plugin.updater.downloadVersionManually = args[0]; - sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Downloading version " + ChatColor.GRAY + args[0] + ChatColor.GREEN + " upon server reload or restart.")); + sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Downloading version " + ChatColor.GRAY + args[0] + ChatColor.GREEN + " upon server restart.")); } }else{ sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms"))); } }else{ - sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpv [update]")); + sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpv [update:latest:cancel]")); } return true; } diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java index 3d8fded..8d98630 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java @@ -429,6 +429,38 @@ public class EditorUserInput implements Listener { savePanelFile(cf, cfile, panelName, panelFile); p.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Removed lore line " + e.getMessage())); break; + case "panel.hotbar.commands.add": + List commandAdd = new ArrayList<>(); + if(cf.contains("open-with-item.commands")){ + commandAdd = cf.getStringList("open-with-item.commands"); + } + commandAdd.add(e.getMessage()); + cf.set("open-with-item.commands", commandAdd); + savePanelFile(cf, cfile, panelName, panelFile); + p.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Added new command: " + e.getMessage())); + break; + case "panel.hotbar.commands.remove": + List commandRemove; + if(cf.contains("open-with-item.commands")){ + commandRemove = cf.getStringList("open-with-item.commands"); + }else{ + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "No commands found to remove!")); + break; + } + try { + commandRemove.remove(Integer.parseInt(e.getMessage())-1); + }catch (Exception ex){ + p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Could not find command!")); + break; + } + if(commandRemove.size() == 0){ + cf.set("open-with-item.commands", null); + }else{ + cf.set("open-with-item.commands", commandRemove); + } + savePanelFile(cf, cfile, panelName, panelFile); + p.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Removed command line " + e.getMessage())); + break; } } diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java index 11b5087..d8919ef 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java @@ -1,7 +1,6 @@ package me.rockyhawk.commandpanels.ingameeditor; import me.rockyhawk.commandpanels.CommandPanels; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -494,6 +493,17 @@ public class EditorUtils implements Listener { p.sendMessage(plugin.papi(plugin.tag + ChatColor.WHITE + "Enter Location (1 to 9)")); p.closeInventory(); } + if(e.getSlot() == 44 && hotbarItems){ + //adds abilities to add and remove lines + if(e.getClick().isLeftClick()) { + plugin.editorInputStrings.add(new String[]{p.getName(),panelName,"panel.hotbar.commands.add"}); + p.sendMessage(plugin.papi(plugin.tag + ChatColor.WHITE + "Enter New Item Command")); + }else{ + plugin.editorInputStrings.add(new String[]{p.getName(),panelName,"panel.hotbar.commands.remove"}); + p.sendMessage(plugin.papi(plugin.tag + ChatColor.WHITE + "Enter command line to remove (must be an integer)")); + } + p.closeInventory(); + } } @EventHandler diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java index 9f32cff..f716d83 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; import java.util.Iterator; import java.util.Objects; diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java index 5c77b52..94fb75b 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java @@ -109,7 +109,7 @@ public class OpenPanelsLoader { } } if (plugin.config.contains("config.panel-snooper")) { - if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) { + if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) { Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + panelName); } } diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index c69262d..7edebf7 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -39,6 +39,13 @@ public class HotbarItemLoader { if(openPanel) { String panelName = plugin.panelNames.get(temp[1])[0]; ConfigurationSection tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(plugin.panelNames.get(temp[1])[1])))).getConfigurationSection("panels." + panelName); + //only open panel automatically if there are no commands + if(tempFile.contains("open-with-item.commands")){ + for(String command : tempFile.getStringList("open-with-item.commands")){ + plugin.commandTags.commandTags(p,plugin.papi(p,command),command); + } + return true; + } if (plugin.openPanels.hasPanelOpen(p.getName())) { plugin.openPanels.skipPanels.add(p.getName()); } @@ -69,6 +76,13 @@ public class HotbarItemLoader { } if(panelItem.isSimilar(invItem)){ if(openPanel) { + //only open panel automatically if there are no commands + if(tempFile.contains("open-with-item.commands")){ + for(String command : tempFile.getStringList("open-with-item.commands")){ + plugin.commandTags.commandTags(p,plugin.papi(p,command),command); + } + return true; + } if (plugin.openPanels.hasPanelOpen(p.getName())) { plugin.openPanels.skipPanels.add(p.getName()); } diff --git a/src/me/rockyhawk/commandpanels/panelblocks/Commandpanelblocks.java b/src/me/rockyhawk/commandpanels/panelblocks/Commandpanelblocks.java index 7898c2c..71cf7b4 100644 --- a/src/me/rockyhawk/commandpanels/panelblocks/Commandpanelblocks.java +++ b/src/me/rockyhawk/commandpanels/panelblocks/Commandpanelblocks.java @@ -22,7 +22,7 @@ public class Commandpanelblocks implements CommandExecutor { @EventHandler public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (label.equalsIgnoreCase("cpb") || label.equalsIgnoreCase("commandpanelsblock") || label.equalsIgnoreCase("cpanelb")) { - if(args.length == 2) { + if(args.length >= 2) { if (args[0].equalsIgnoreCase("add")) { if(!(sender instanceof Player)) { sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Please execute command as a Player!")); @@ -52,7 +52,9 @@ public class Commandpanelblocks implements CommandExecutor { } Location blockLocation = blockType.getLocation(); String configValue = "blocks." + Objects.requireNonNull(blockLocation.getWorld()).getName().replaceAll("_", "%dash%") + "_" + blockLocation.getBlockX() + "_" + blockLocation.getBlockY() + "_" + blockLocation.getBlockZ() + ".panel"; - plugin.blockConfig.set(configValue, args[1]); + //this is simply getting all of the args values after the add + String panelValue = String.join(" ", args).replace("add ", ""); + plugin.blockConfig.set(configValue, panelValue); try { plugin.blockConfig.save(new File(plugin.getDataFolder() + File.separator + "blocks.yml")); } catch (IOException e) { diff --git a/src/me/rockyhawk/commandpanels/panelblocks/PanelBlockOnClick.java b/src/me/rockyhawk/commandpanels/panelblocks/PanelBlockOnClick.java index 15d22cf..ab5150d 100644 --- a/src/me/rockyhawk/commandpanels/panelblocks/PanelBlockOnClick.java +++ b/src/me/rockyhawk/commandpanels/panelblocks/PanelBlockOnClick.java @@ -3,14 +3,12 @@ package me.rockyhawk.commandpanels.panelblocks; import me.rockyhawk.commandpanels.CommandPanels; import org.bukkit.Location; import org.bukkit.block.Block; -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.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import java.io.File; import java.util.Objects; public class PanelBlockOnClick implements Listener { @@ -41,16 +39,15 @@ public class PanelBlockOnClick implements Listener { Location tempLocation = new Location(plugin.getServer().getWorld(loc[0].replaceAll("%dash%","_")),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]),Double.parseDouble(loc[3])); if(tempLocation.equals(block.getLocation())){ e.setCancelled(true); - for(String[] temp : plugin.panelNames){ - if(temp[0].equals(plugin.blockConfig.getString("blocks." + configLocation + ".panel"))){ - String panelName = temp[0]; - YamlConfiguration cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(temp[1])))); - if(!plugin.openPanels.hasPanelOpen(p.getName())) { - plugin.openVoids.openCommandPanel(p, p, panelName, cf.getConfigurationSection("panels." + panelName), false); - } - return; + if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){ + for(String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")){ + plugin.commandTags.commandTags(p,plugin.papi(p,command),command); } + return; } + //uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders + String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel"); + plugin.commandTags.commandTags(p, plugin.papi(p, command), command); } } } diff --git a/src/me/rockyhawk/commandpanels/updater/Updater.java b/src/me/rockyhawk/commandpanels/updater/Updater.java index c0b2d3a..a720059 100644 --- a/src/me/rockyhawk/commandpanels/updater/Updater.java +++ b/src/me/rockyhawk/commandpanels/updater/Updater.java @@ -50,8 +50,8 @@ public class Updater { if(sendMessages) { Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.GOLD + " ================================================"); Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.AQUA + " An update for CommandPanels is available."); - Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + " Download CommandPanels " + ChatColor.GOLD + gitVersion + ChatColor.WHITE + " here:"); - Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.AQUA + " https://www.spigotmc.org/resources/command-panels-custom-guis.67788/"); + Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + " Download CommandPanels " + ChatColor.GOLD + gitVersion + ChatColor.WHITE + " using the"); + Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.WHITE + " following command:" + ChatColor.AQUA + " /cpv latest" + ChatColor.WHITE + " and restart the server"); Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.GOLD + " ================================================"); } } @@ -79,8 +79,8 @@ public class Updater { return; } - if(latestVersion.equals(thisVersion)){ - //no need to update + if(latestVersion.equals(thisVersion) || thisVersion.contains("-")){ + //no need to update or running custom version return; } if(Objects.equals(plugin.config.getString("config.updater.minor-updates-only"), "true")){