I was making a plugin where /more would give you a full stack of the item unless in the configuration file it blocked that item from being duplicated. At the moment the plugin only works if the player is op or has the permission more.more because it bypasses the main code. I'm not sure why this happens. Any help would be appreciated. Code: Code:java @SuppressWarnings("deprecation") public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("more")){ ItemStack stack = player.getInventory().getItemInHand(); if(!player.hasPermission("more.more")){ int item = player.getItemInHand().getTypeId(); String hand = "" + item; List<String> blocked = plugin.getConfig().getStringList("BlockedItems"); for (String block : blocked) { if(!(block == hand)){ stack.setAmount(64); }else{ player.sendMessage(ChatColor.DARK_RED + "Error: " + ChatColor.RED + "You May Not Duplicate That Item!"); } } }stack.setAmount(64); } return false;} Also Here Is My Config Code: BlockedItems: - 0001 - 0002 - 0003 EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Found your problem. you cant compare the contents of a string using == you have to use .equals() EDIT: My bad the above line might help. Should the player need the permission when he/she types the command?
agent6262 I think I fixed it right but it still doesnt work. New Code: Code:java @SuppressWarnings("deprecation") public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("more") && (player.getItemInHand()) !=null){ ItemStack stack = player.getInventory().getItemInHand(); if(!player.hasPermission("more.more")){ int item = player.getItemInHand().getTypeId(); String hand = "" + item; List<String> blocked = plugin.getConfig().getStringList("BlockedItems"); for (String block : blocked) { if(!block.equals(hand)){ stack.setAmount(64); }else{ player.sendMessage(ChatColor.DARK_RED + "Error: " + ChatColor.RED + "You May Not Duplicate That Item!"); } } }stack.setAmount(64); } return false;}
Wouldn't you use Code:java cmd.getName().equalsIgnoreCase("more"); instead of Code:java commandLabel.equalsIgnoreCase("more")
agent6262 No. Its cmd.getName() not commanLabel zakarls What is not working now? Do you get any errors?
sipsi133 and agent6262 The commandLabel works just fine. As I said in the first post the plugin works fine if im op because stated here, Code:java if(!player.hasPermission("more.more") it would bypass the main code. So I think that there is a problem in this section: Code:java int item = player.getItemInHand().getTypeId(); String hand = "" + item; List<String> blocked = plugin.getConfig().getStringList("BlockedItems"); for (String block : blocked) { if(!block.equals(hand)){ stack.setAmount(64); }else{ player.sendMessage(ChatColor.DARK_RED + "Error: " + ChatColor.RED + "You May Not Duplicate That Item!"); } or something terribly off in the config. Sorry for shooting down your ideas, but I just dont think thats the issue.
zakarls So if the player has the permission "more.more" should he/she be able to use the command? sipsi133 That's what i said, he should be using cmd.getName();
Then wouldn't you do this Code:java @SuppressWarnings("deprecation")public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("more") && (player.getItemInHand()) !=null){ ItemStack stack = player.getInventory().getItemInHand(); if(player.hasPermission("more.more")){//Fix HERE int item = player.getItemInHand().getTypeId(); String hand = "" + item; List<String> blocked = plugin.getConfig().getStringList("BlockedItems"); for (String block : blocked) { if(!block.equals(hand)){ stack.setAmount(64); }else{ player.sendMessage(ChatColor.DARK_RED + "Error: " + ChatColor.RED + "You May Not Duplicate That Item!"); } } } stack.setAmount(64); } return false;}
agent6262 Oh. I see where you are coming from. I said that wrong. Sorry. How it works is that anyone can use the plugin, but if you have the permission more.more you bypass the code and are able to duplicate the banned blocks. If you dont have that permission you can still use the plugin but if the block is banned in the config you cant duplicate it... I hope this clears things up. I now realize i was unclear when stating what this permission does
Oh ok, give me 3 hours and i should have a solution for you; have to do family stuff. Tell me how this goes Code:java @SuppressWarnings("deprecation")public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("more") && (player.getItemInHand()) !=null){ ItemStack stack = player.getInventory().getItemInHand(); if(player.hasPermission("more.more")){//Fix HERE stack.setAmount(64); } else{ int item = player.getItemInHand().getTypeId(); String hand = "" + item; List<String> blocked = plugin.getConfig().getStringList("BlockedItems"); for (String block : blocked) { if(!block.equals(hand)){ stack.setAmount(64); }else{ player.sendMessage(ChatColor.DARK_RED + "Error: " + ChatColor.RED + "You May Not Duplicate That Item!"); } } } return true; } return false;} P.S. the problem was that when you execute a command and it works you have to return true; EDIT by Moderator: merged posts, please use the edit button instead of double posting.