plugin.yml Code: name: ToxicBans main: me.Vinceguy1.ToxicBans.Main version: 1.0 description: Gives you admin commands! commands: Ban: description: Ban those pesky players! aliases: [tban,toxicban] Tempban: description: Tempban those pesky players! aliases: [ttempban,toxictempban] Kick: description: Kick those pesky players! aliases: [tkick,toxickick] I honestly can't figure out what is wrong.
Code: public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(cmd.getName().equalsIgnoreCase("ban")) { CommandBan.Command(sender, args); } if(cmd.getName().equalsIgnoreCase("kick")) { CommandKick.Command(sender, args); } if(cmd.getName().equalsIgnoreCase("tempban")) { CommandTempban.Command(sender, args); } return true; } It can't be that though because it says its an unkown command, if it was this it wouldn't do anything Help? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Are you typing commands in game with an uppercase as well? Bukkit will always check if the command exits before you your executor can even check what command it is. on that note, separate command executors go a long way in cleaning up code..
^^ Yea it just might be little things.... you could even try Code: if(cmd.equalsIgnoreCase("blah")) // instead of if(cmd.getName().equalsIgnoreCase("blah"))
the first one wouldn't work because cmd is a Command object and you would be trying to compare it to a String
These if statements have no effect on Bukkit knowing about the command. With different command executors you do not even have to check. Vinceguy1 The commands have to be in the plugin.yml. I am however not sure it they have to be lower case. i.e. blah and Blah are different commands
I believe they have to be lowercase. I would also use commanLabel.equalsIgnoreCase. It's the way I do it for all my plugins, and I've never had any trouble with it
If you're passing each command off to another class anyway, why not simply make those classes CommandExecutor? Then you don't have to worry about sending the commands out at all, you simply register each command to it's own executor.
Main Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { public final PlayerListener playerListener = new PlayerListener(); public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this.playerListener, this); Config.message = getConfig(); me.Vinceguy1.ToxicBans.Config.Config(); saveConfig(); System.out.println("ToxicBans v1.0 {By Vinceguy1} is now enabled!"); } public void onDisable() { System.out.println("ToxicBans v1.0 {By Vinceguy1} is now disabled!"); } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(cmd.getName().equalsIgnoreCase("ban")) { CommandBan.Command(sender, args); } if(cmd.getName().equalsIgnoreCase("kick")) { CommandKick.Command(sender, args); } if(cmd.getName().equalsIgnoreCase("tempban")) { CommandTempban.Command(sender, args); } return true; } } CommandBan Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandBan { public static void Command(CommandSender sender, String[] args) { if(sender.hasPermission(Config.message.get("Permissions.Ban").toString())) { if(args.length < 1) { sender.sendMessage(Config.message.get("Messages.Not Enough Arguments").toString()); } if(args.length == 1) { Player player = Bukkit.getPlayer(args[0]); if(player != null) { FileBan.WriteBan(player, Config.message.get("Messages.Default Reason").toString(), sender); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } if(args.length > 1) { Player player = Bukkit.getPlayer(args[0]); StringBuilder s = new StringBuilder(); for(int i = 1; i < args.length; i++) { s.append(args[i] + " "); } s.setLength(s.length() - 1); if(player != null) { FileBan.WriteBan(player, s.toString(), sender); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } } else { sender.sendMessage(Config.message.get("Messages.No Permission").toString()); } } } CommandKick class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandKick { public static Main plugin; public static void Command(CommandSender sender, String[] args) { if(sender.hasPermission(Config.message.get("Permissions.Ban").toString())) { if(args.length < 1) { sender.sendMessage(Config.message.get("Messages.Not Enough Arguments").toString()); } if(args.length == 1) { Player player = Bukkit.getPlayer(args[0]); if(player != null) { String BroadcastKick = Config.message.get("Broadcast Kick").toString(); String BroadcastMessage = BroadcastKick.replace("<ADMIN>", sender.getName()); BroadcastMessage = BroadcastMessage.replace("<PLAYER>", player.getName()); BroadcastMessage = BroadcastMessage.replace("<REASON>", Config.message.get("Messages.No Reason").toString()); String Message = Config.message.get("Messages.Kick Message Kick").toString(); Message = Message.replace("<PLAYER>", player.getName()); Message = Message.replace("<ADMIN>", sender.getName()); Message = Message.replace("<REASON>", Config.message.get("Messages.No Reason").toString()); player.kickPlayer(Message); Bukkit.broadcastMessage(BroadcastMessage); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } if(args.length > 1) { Player player = Bukkit.getPlayer(args[0]); if(player != null) { String BroadcastKick = Config.message.get("Messages.Broadcast Kick").toString(); String BroadcastMessage = BroadcastKick.replace("<ADMIN>", sender.getName()); BroadcastMessage = BroadcastMessage.replace("<PLAYER>", player.getName()); StringBuilder s = new StringBuilder(); for(int i = 1; i < args.length; i++) { s.append(args[i] + " "); } BroadcastMessage = BroadcastMessage.replace("<REASON>", s.toString()); String Message = Config.message.get("Messages.Kick Message Kick").toString(); Message = Message.replace("<PLAYER>", player.getName()); Message = Message.replace("<ADMIN>", sender.getName()); Message = Message.replace("<REASON>", s.toString()); player.kickPlayer(Message); Bukkit.broadcastMessage(BroadcastMessage); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } } else { sender.sendMessage(Config.message.get("Messages.No Permission").toString()); } } } CommandTempban Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandTempban { public static void Command(CommandSender sender, String[] args) { if(sender.hasPermission(Config.message.get("Permissions.Tempban").toString())) { if(args.length < 1) { sender.sendMessage(Config.message.get("Messages.Not Enough Arguments").toString()); } if(args.length == 1) { Player player = Bukkit.getPlayer(args[0]); if(player != null) { FileTempban.WriteBan(player, Config.message.get("Messages.Default Bantime"), sender); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } if(args.length > 1) { Player player = Bukkit.getPlayer(args[0]); if(player != null) { FileTempban.WriteBan(player, args[1], sender); } else { sender.sendMessage(Config.message.get("Messages.Player Not Found").toString()); } } } else { sender.sendMessage(Config.message.get("Messages.No Permission").toString()); } } } Config Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; public class Config extends JavaPlugin { public static FileConfiguration message; public static void Config() { if(message.get("Messages") == null) { message.createSection("Messages"); } if (message.get("Messages.Player Not Found") == null) { message.set("Messages.Player Not Found", "§cError: Player not found!"); } if (message.get("Messages.No Permission") == null) { message.set("Messages.No Permission", "§cError: You do not have permission!"); } if(message.get("Messages.Not Enough Arguments") == null) { message.set("Messages.Not Enough Arguments", "§cError: Not enough args!"); } if(message.get("Messages.Kick Message Ban") == null) { message.set("Messages.Kick Message Ban", "<ADMIN> has banned you for <REASON> appeal your ban on www.toxicpvp.net!"); } if(message.get("Messages.Kick Message Tempban") == null) { message.set("Messages.Kick Message Tempban", "You are temporarily banned for <TIME>!"); } if(message.get("Messages.Kick Message Kick") == null) { message.set("Message.Kick Message Kick", "<ADMIN> has kicked you for <REASON>."); } if(message.get("Messages.Broadcast Ban") == null) { message.set("Messages.Broadcast Ban", "§c<ADMIN> §ehas banned §c<PLAYER> §efor §c<REASON>"); } if(message.get("Messages.Broadcast Tempban") == null) { message.set("Messages.Broadcast Tempban", "§c<ADMIN> §ehas temporarily banned §c<PLAYER> §efor §c<TIME>"); } if(message.get("Messages.Broadcast Kick") == null) { message.set("Messages.Broadcast Kick", "§c<ADMIN> §ehas kicked §c<PLAYER> §efor §c<REASON>"); } if(message.get("Messages.Default Reason") == null) { message.set("Messages.Default Reason", "§eYou have been banned!"); } if(message.get("Messages.Default Bantime") == null) { message.set("Messages.Default Bantime", "60"); } if(message.get("Permissions") == null) { message.createSection("Permissions"); } if(message.get("Permissions.Ban") == null) { message.set("Permissions.Ban", "toxicbans.ban"); } if(message.get("Permissions.Tempban") == null) { message.set("Permissions.Tempban", "toxicbans.tempban"); } if(message.get("Permissions.Kick") == null) { message.set("Permissions.Kick", "toxicbans.kick"); } } } FileBan class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class FileBan { public static void WriteBan(Player player, String Reason1, CommandSender sender) { try { File BanDirectory = new File("plugins/ToxicBans/Bans/"); if(!BanDirectory.exists()); { BanDirectory.mkdir(); } File Ban = new File("plugins/ToxicBans/Bans/" + player.getName() + ".txt"); String Reason = Config.message.get("Messages.Kick Message Ban").toString(); Reason = Reason.replace("<PLAYER>", player.getName()); Reason = Reason.replace("<ADMIN>", sender.getName()); Reason = Reason.replace("<REASON>", Reason1); BufferedWriter TimeWrite = new BufferedWriter(new FileWriter(Ban)); TimeWrite.write(Reason); TimeWrite.write(sender.getName()); TimeWrite.close(); player.kickPlayer(Reason); } catch (Exception ex) { sender.sendMessage("Error!"); } } } FileTempban Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: package me.Vinceguy1.ToxicBans; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class FileTempban { public static void WriteBan(Player player, Object Add, CommandSender sender) { try { File TempbanDirectory = new File("plugins/ToxicBans/Tempbans/"); if(!TempbanDirectory.exists()); { TempbanDirectory.mkdir(); } File Tempban = new File("plugins/ToxicBans/Tempbans/" + player.getName() + ".txt"); BufferedWriter TimeWrite = new BufferedWriter(new FileWriter(Tempban)); long Time = System.currentTimeMillis(); long TimeDifference = Long.parseLong((String) Add); TimeDifference = TimeDifference * 60000; long BanTime1 = Time + TimeDifference; String BanTime = String.valueOf(BanTime1); TimeWrite.write(BanTime + "\r\n"); TimeWrite.write(sender.getName()); TimeWrite.close(); player.kickPlayer(Config.message.get("Messages.Kick Message Tempban").toString()); } catch (Exception ex) { sender.sendMessage("Error!"); } } } PlayerListener Class Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler package me.Vinceguy1.ToxicBans; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerLogin(PlayerLoginEvent event) { try { BufferedReader BanTime = new BufferedReader(new FileReader("plugins/ToxicBans/Tempbans/" + event.getPlayer().getName() + ".txt")); String Time1 = BanTime.readLine(); String Line2 = BanTime.readLine(); BanTime.close(); Long Time = Long.parseLong(Time1); if(System.currentTimeMillis() >= Time) { File TempBanFile = new File("plugins/ToxicBans/Tempbans/" + event.getPlayer().getName() + ".txt"); TempBanFile.delete(); } else { Object Reason1 = Config.message.get("Messages.Kick Message Tempban"); String Reason4 = String.valueOf(Reason1); String Reason2 = Reason4.replace("<ADMIN>", Line2); String Reason3 = Reason2.replace("<PLAYER>", event.getPlayer().getName()); Long WaitTime1 = Time - System.currentTimeMillis(); Long WaitTime2 = WaitTime1 / 60000; event.getPlayer().sendMessage("test1"); String WaitTime = String.valueOf(WaitTime2); if(WaitTime2 < 1) { long WaitTimeInt2 = WaitTime1 /1000; String WaitTimeFinal = String.valueOf(WaitTimeInt2); String Reason = Reason3.replace("<TIME>", WaitTimeFinal + " seconds"); event.disallow(Result.KICK_BANNED, Reason); } else { String Reason = Reason3.replace("<TIME>", WaitTime + " minutes"); event.disallow(Result.KICK_BANNED, Reason); } } } catch(Exception ex) { } try { BufferedReader BanTime = new BufferedReader(new FileReader("plugins/ToxicBans/Bans/" + event.getPlayer().getName() + ".txt")); String Reason = BanTime.readLine(); String Admin = BanTime.readLine(); BanTime.close(); String KickMessage = Config.message.get("Messages.Kick Message Ban").toString(); KickMessage = KickMessage.replace("<ADMIN>", Admin); KickMessage = KickMessage.replace("<REASON>", Reason); event.disallow(Result.KICK_BANNED, KickMessage); } catch(Exception ex) { } } } NVM i figured it out EDIT by Moderator: merged posts, please use the edit button instead of double posting.