Solved Custom Ban

Discussion in 'Spigot Plugin Help' started by MrFishCakes, Jun 25, 2016.

  1. Hello! I am making a plugin for a server I am the developer on (the plugin is for the staff) and I want a custom ban message. Example:
    /ban MrFishCakes Being a noob
    It would say that to the player that was banned. Here is the code I believe I have made the custom "banReason" string wrong. Any help is appreciated!
    Code (Text):
    package com.mrfishcakes.fblock.staffcommands;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Ban implements CommandExecutor {

        @SuppressWarnings({ "null", "deprecation" })
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

            if (cmd.getName().equalsIgnoreCase("ban")) {
                if (!sender.hasPermission("fblock.ban")) {
                    sender.sendMessage(ChatColor.RED + "You don't have permission!");
                    if (args.length == 0) {
                        sender.sendMessage(ChatColor.RED + "Enter a player to ban!");
                        return true;
                    String banReason = null;
                    if(banReason.length() == 0) {
                        sender.sendMessage(ChatColor.RED + "Please enter a reason to ban!");
                        return true;
                    Player target = Bukkit.getServer().getPlayer(args[0]);
                    sender.sendMessage(ChatColor.GREEN + "Successfully banned " + ChatColor.RED + args[0]
                            + ChatColor.GREEN + " for " + banReason);
                    return true;
            return false;
  2. You don't have to do target.setBanned(true);
    Its better to do: Bukkit.getBanList(BanList.Type.NAME).addBan(target.getName(), banReason, null, sender.getName())
  3. Thank you! Do you know if I can set a custom ban message?
  4. Wrong sections, should be in plugin development