Hey everybody, I'm making a plugin, but when I test it, only 2 of the three commands work. I am 100% sure I did the plugin.yml right. I will be so grateful if someone could help! I've made plugins before, but that was a long time ago, and I'm a little rusty. Thanks in advance! Here's my code: Code:java package BDKing88; import java.util.logging.Logger; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType; public class SimpleBlind extends JavaPlugin implements Listener{ public SimpleBlind plugin; Logger log = Logger.getLogger("Minecraft"); public void onEnable() {PluginDescriptionFile pdfFile = this.getDescription();this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been enabled.");} public void onDisable() {PluginDescriptionFile pdfFile = this.getDescription();this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been disabled.");} public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player s = (Player) sender; if(cmd.getName().equalsIgnoreCase("blind")) {if(args.length == 0) {s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /blind [player]"); } else { if(args.length == 1)if(sender.hasPermission("sb.blind")) {sender.sendMessage(ChatColor.GREEN + "Player blinded!");Player targetPlayer = s.getServer().getPlayer(args[1]);targetPlayer.sendMessage(ChatColor.GREEN + "You have been blinded by " + ChatColor.GOLD + sender.getName());targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5000, 1)); } else { if(cmd.getName().equalsIgnoreCase("unblind")) {if(args.length == 0) {s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /unblind [player]"); } else { if(args.length == 1){if(sender.hasPermission("sb.unblind")) {sender.sendMessage(ChatColor.GREEN + "Player unblinded!");Player targetPlayer = s.getServer().getPlayer(args[1]);targetPlayer.sendMessage(ChatColor.GREEN + "You have been unblinded by " + ChatColor.GOLD + sender.getName());targetPlayer.getActivePotionEffects().clear();} if (cmd.getName().equalsIgnoreCase("simpleblind")) {sender.sendMessage(ChatColor.GREEN + " -=[SimpleBlind] Commands/Info=-");sender.sendMessage(ChatColor.GREEN + "/blind [Player] - Blinds the player.");sender.sendMessage(ChatColor.GREEN + "/unblind [Player] - Unblinds the player.");sender.sendMessage(ChatColor.GREEN + "/simpleblind - Shows this message again.");sender.sendMessage(ChatColor.GREEN + "-----------------------------------------------------");sender.sendMessage(ChatColor.YELLOW + " SimpleBlind was created by BDKing88.");return true; }
Yes, I added all the commands and all the perms. I did the right spacing and everything, and yes, I did refresh the project.
BDKing88 What is the error of the third command? Uknown Command? I also give you a tip. Use spaces in your code. It is difficult to read now. What is the command that is not working?
No text comes up, nothing happens. The ones that work: /blind and /simpleblind. The command that doesent work /unblind. I have no idea why. :/
I think u have the brackets wrong i added a few see if it works like this Code: package BDKing88; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; public class SimpleBlind extends JavaPlugin implements Listener{ public SimpleBlind plugin; Logger log = Logger.getLogger("Minecraft"); public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been enabled."); } public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been disabled."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player s = (Player) sender; if(cmd.getName().equalsIgnoreCase("blind")) { if(args.length == 0) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /blind [player]"); } else { if(args.length == 1) { if(sender.hasPermission("sb.blind")) { sender.sendMessage(ChatColor.GREEN + "Player blinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been blinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5000, 1)); } } else { if(cmd.getName().equalsIgnoreCase("unblind")) { if(args.length == 0) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /unblind [player]"); } else { if(args.length == 1){ if(sender.hasPermission("sb.unblind")) { sender.sendMessage(ChatColor.GREEN + "Player unblinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been unblinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.getActivePotionEffects().clear(); } if (cmd.getName().equalsIgnoreCase("simpleblind")) { sender.sendMessage(ChatColor.GREEN + " -=[SimpleBlind] Commands/Info=-"); sender.sendMessage(ChatColor.GREEN + "/blind [Player] - Blinds the player."); sender.sendMessage(ChatColor.GREEN + "/unblind [Player] - Unblinds the player."); sender.sendMessage(ChatColor.GREEN + "/simpleblind - Shows this message again."); sender.sendMessage(ChatColor.GREEN + "-----------------------------------------------------"); sender.sendMessage(ChatColor.YELLOW + " SimpleBlind was created by BDKing88."); return true; }
BDKing88 Use debugging and check where it is wrong. plugin.yml is correct because the error is not: "unkown command" BDKing88 I think i now the error. Change: Code:java if(sender.hasPermission("sb.blind")) { To: Code:java if(sender.hasPermission("sb.blind") || sender.isOp() == true){ And add a else for the permission check because the otherways happens nothing if the player has no permissions. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Try like this and u can set the permissions in the yml file Code: public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("blind")) return commandBlind(sender, args); if (cmd.getName().equalsIgnoreCase("unblind")) return commandUnblind(sender, args); if (cmd.getName().equalsIgnoreCase("simpleblind")) return commandSimpleblind(sender, args); return true; } private boolean commandBlind(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.GREEN + "Player blinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been blinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5000, 1)); return true; } private boolean commandUnblind(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.GREEN + "Player unblinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been unblinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.getActivePotionEffects().clear(); return true; } private boolean commandSimpleblind(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.GREEN + " -=[SimpleBlind] Commands/Info=-"); sender.sendMessage(ChatColor.GREEN + "/blind [Player] - Blinds the player."); sender.sendMessage(ChatColor.GREEN + "/unblind [Player] - Unblinds the player."); sender.sendMessage(ChatColor.GREEN + "/simpleblind - Shows this message again."); sender.sendMessage(ChatColor.GREEN + "-----------------------------------------------------"); sender.sendMessage(ChatColor.YELLOW + " SimpleBlind was created by BDKing88."); return true; }
Yea, the entire thing is screwed up. None of the commands work. So which persons advice should I follow?
Well, there are a few things in your code which is / can be making trouble. First, Tim4209 was right. You are missing quite a few brackets, while you also have some in places you shouldn't. I took the freedom to organize this a little, here it is: Code:java package BDKing88; import java.util.logging.Logger; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType; public class SimpleBlind extends JavaPlugin implements Listener{ public SimpleBlind plugin; Logger log = Logger.getLogger("Minecraft"); public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been enabled."); } public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "] " + pdfFile.getVersion() + " has been disabled."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player s = (Player) sender; if (cmd.getName().equalsIgnoreCase("blind")) { if (args.length == 0) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /blind [player]"); } else if (args.length == 1) { if (sender.hasPermission("sb.blind")) { sender.sendMessage(ChatColor.GREEN + "Player blinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been blinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5000, 1)); } } } else if(cmd.getName().equalsIgnoreCase("unblind")) { if(args.length == 0) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /unblind [player]"); } else if(args.length == 1){ if(sender.hasPermission("sb.unblind")) { sender.sendMessage(ChatColor.GREEN + "Player unblinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.GREEN + "You have been unblinded by " + ChatColor.GOLD + sender.getName()); targetPlayer.getActivePotionEffects().clear(); } } } else if (cmd.getName().equalsIgnoreCase("simpleblind")) { sender.sendMessage(ChatColor.GREEN + " -=[SimpleBlind] Commands/Info=-"); sender.sendMessage(ChatColor.GREEN + "/blind [Player] - Blinds the player."); sender.sendMessage(ChatColor.GREEN + "/unblind [Player] - Unblinds the player."); sender.sendMessage(ChatColor.GREEN + "/simpleblind - Shows this message again."); sender.sendMessage(ChatColor.GREEN + "-----------------------------------------------------"); sender.sendMessage(ChatColor.YELLOW + " SimpleBlind was created by BDKing88."); return true; } return false; }} If you adapt your code to look exactly like this, all 3 commands should have some effect. Either they work, or they give an "Internal Error"-Message - which is at least something Try to change it, recompile it and see if now all 3 commands do something - either a chat display or an error message. Once you got that, we can look into the other errors
I noticed you had no else clause checking for more arguments on unblind. Are you sure you are sending it with 0 or 1 args?
1, doesent that mean /unblind [player] ? Ok, I recoded it, it's neater and I fixed the brackets, but it still doesent work. code: Code:java package BDKing88; import java.util.logging.Logger; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType; public class SimpleB extends JavaPlugin { public SimpleB plugin; Logger log = Logger.getLogger("Minecraft"); public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "]" + " has been disabled"); } public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info("[" + pdfFile.getName() + "]" + " has been enabled"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player s = (Player) sender; if(cmd.getName().equalsIgnoreCase("blind")) { if((!(sender instanceof Player) && args.length == 0)) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /blind [Player]"); } if(args.length == 1) { if(s.hasPermission("sb.blind") || sender.isOp() == true) { s.sendMessage(ChatColor.GREEN + "Player blinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.YELLOW + "You have been blinded by " + s.getName()); targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5000, 1)); } if(cmd.getName().equalsIgnoreCase("unblind")) { if((!(sender instanceof Player) && args.length == 0)) { s.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage: /unblind [Player]"); } if(args.length == 1) { if(s.hasPermission("sb.unblind") || sender.isOp() == true) { s.sendMessage(ChatColor.GREEN + "Player unblinded!"); Player targetPlayer = s.getServer().getPlayer(args[1]); targetPlayer.sendMessage(ChatColor.YELLOW + "You have been unblinded by " + s.getName()); targetPlayer.getActivePotionEffects().clear(); } if(cmd.getName().equalsIgnoreCase("simpleblind")) { if((!(sender instanceof Player) && args.length < 0)) { s.sendMessage("Incorrect usage. Correct usage: /simpleblind"); } s.sendMessage(ChatColor.GREEN + " -=[SimpleBlind]=-"); s.sendMessage(ChatColor.GREEN + "/blind [Player] - Blinds player."); s.sendMessage(ChatColor.GREEN + "/unblind [Player] - Unblinds the player."); s.sendMessage(ChatColor.GREEN + "/simpleblind - Takes you back to these commands."); s.sendMessage(ChatColor.GREEN + "------------------------------------------------"); s.sendMessage(ChatColor.YELLOW + " Plugin made by: BDKing88."); } } } } } return false; } } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code:java if(cmd.getName().equalsIgnoreCase("blind")) { ... if(cmd.getName().equalsIgnoreCase("unblind")) { Take a closer look. How could the second if statement ever be true if the first one is? But the second one will only be called if the first one is true.
So, how would I make it disable /blind when it is true? Tim, I don't see what you changed because I'm a noob. Could you please explain? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
i put every command into its own method, so it would be almost impossible for you to mess the brackets up and not notice it
Okay, I did that tim, but now the plugin won't load into the server. It gives no errors, it just doesen't show up. I'm having the worst luck today :/