Hello Guys, I making ChatBot plugin which will contains all importants things for server, like Anti-Curse, Anti-Spam, MOTDs, Answers, Announces and much more. But I'm here to ask you for help with issues in my plugin. Right now, I working on CommandsExecution, for some reasons, default command "/chatbot" or "/chatbot help" for help works fine, but problem is with other args commands, I try to repair all visible errors in console but it looks like commands are not executed. I'll put you script down here: Code:java package sk.mahl11.chatbot; import java.io.File; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.configuration.file.FileConfiguration;import org.bukkit.configuration.file.YamlConfiguration;import org.bukkit.entity.Player; public class Commands implements CommandExecutor { Main plugin; //FileConfiguration config; File cf; public Commands(Main plugin){ this.plugin = plugin; } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { String chatbot = plugin.getConfig().getString("chatbot-name").replaceAll("&", "§"); if(sender instanceof Player){ Player player = (Player) sender; if(!sender.hasPermission("chatbot") || (!sender.isOp())){ sender.sendMessage(chatbot + ChatColor.RED + ChatColor.BOLD + " You dont have permission for that!"); return true; } else if(cmd.getName().equalsIgnoreCase("chatbot")){ if(args.length == 0 || args[0].equals("help")){ //Help sender.sendMessage(ChatColor.GOLD + "---------[ " + chatbot + "]---------"); sender.sendMessage("- /chatbot help"); sender.sendMessage("- /chatbot motd <message>"); sender.sendMessage(ChatColor.GOLD + "---------[ " + chatbot + "]---------"); } } else if(!sender.hasPermission("chatbot.admin") || (!sender.isOp())){ sender.sendMessage(chatbot + ChatColor.RED + ChatColor.BOLD + " You are not Admin!"); return true; }else{ if(args[0].equalsIgnoreCase("reload")){ //Reload Config FileConfiguration config = YamlConfiguration.loadConfiguration(cf); return true; } else if(args[0].equalsIgnoreCase("announce")){ //Adding Messages } else if(args[0].equalsIgnoreCase("motd")){ if(args.length == 1){ sender.sendMessage(chatbot + ChatColor.RED + "Please specify a message!"); return true; } // I'll } } } /* StringBuilder str = new StringBuilder(); for(int i = 1; i < args.length+1; i++){ str.append(args[I] + " "); } String motd = str.toString(); plugin.getConfig().set("motd", motd); plugin.saveConfig(); sender.sendMessage(chatbot + "MOTD is now: " + motd);*/ return true; } }[/I] I really don't know how fix it, I'll be happy if you help me with it Thank you!
You got there a little mistake I think. Use an other permission (not only "chatbot") like "chatbot.default" - Check first if the command equals "chatbot". - Then check if the player is OP or has the permission - Now check if there are some arguments - Finally do what you wish for Also use: Code: if(player.hasPermission("something.something")) { //do stuff } else { //no permission-message } instead of checking if the player doesn´t have the permission and then go ahead. I really hope I could help you, if you got more questions: reply to me
You are getting this problem because of a logic error What this is saying is to check for the other commands only if the command sent is not chatbot. To fix this, fix your encapsulation. I highly recommend fixing your format, as that will help you (and anyone else reading your code) see errors like this.