kickPlayer creates null message

Discussion in 'Server & Community Management' started by Atomicbeast101, Mar 2, 2013.

  1. I know spigot doesnt take api calls. But can someone give me an example on how to get the player and kick them along with the message? My plugin is way too huge to be posted here. But heres the code line if your wondering: player.kickPlayer(message);
     
  2. Paste the code.
    Did you tried: String message = "You have been kicked by: Admin";
     
    • Optimistic Optimistic x 1
  3. NukeChat.java Main class:
    Code (Text):
    package com.chaoticunited;
     
    import java.io.File;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class NukeChat extends JavaPlugin
    {
        public NukeChat log;
        public static Integer seconds_between_message;
        public static boolean swear_kick;
        public static boolean swear_warn;
        public static boolean caps_kick;
        public static boolean caps_warn;
        public static boolean caps_reducemessage;
        public static boolean advertise_kick;
        public static boolean advertise_warn;
        public static String swear_kick_message;
        public static String caps_kick_message;
        public static String spam_kick_message;
        public static String swear_warn_message;
        public static String caps_warn_message;
        public static String advertise_kick_message;
        public static String advertise_warn_message;
        public static String join_message;
        public static String quit_message;
        public static DataBase swearlist;
        public static HashMap<String, Long> spamlist;
        public static HashMap<String, Integer> countlist;
        public void onDisable()
        {
            Logger.getLogger("Minecraft").info("[NukeChat] Nuke's plugin is disabled!");
        }
        @SuppressWarnings("deprecation")
        public void onEnable()
        {
            File file = new File(getDataFolder(), "config.yml");
            if(!file.exists())
            {
                saveDefaultConfig();
                seconds_between_message = getConfig().getInt("seconds-between-message");
                swear_kick = getConfig().getBoolean("swear.kick-player");
                swear_warn = getConfig().getBoolean("swear.warn-player");
                caps_kick = getConfig().getBoolean("caps.kick-player");
                caps_warn = getConfig().getBoolean("caps.warn-player");
                caps_reducemessage = getConfig().getBoolean("caps.reducemessage-player");
                advertise_kick = getConfig().getBoolean("advertise.kick-player");
                advertise_warn = getConfig().getBoolean("advertise.warn-player");
                swear_kick_message = getConfig().getString("swear.kick-message");
                caps_kick_message = getConfig().getString("caps.kick-message");
                spam_kick_message = getConfig().getString("spam.kick-message");
                swear_warn_message = getConfig().getString("swear.warn-message");
                caps_warn_message = getConfig().getString("caps.warn-message");
                advertise_kick_message = getConfig().getString("advertise.kick-message");
                advertise_warn_message = getConfig().getString("advertise.warn-message");
                join_message = getConfig().getString("join-message");
                quit_message = getConfig().getString("quit-message");
                saveConfig();
            }
            else
            {
                seconds_between_message = getConfig().getInt("seconds-between-message");
                swear_kick = getConfig().getBoolean("swear.kick-player");
                swear_warn = getConfig().getBoolean("swear.warn-player");
                caps_kick = getConfig().getBoolean("caps.kick-player");
                caps_warn = getConfig().getBoolean("caps.warn-player");
                caps_reducemessage = getConfig().getBoolean("caps.reducemessage-player");
                advertise_kick = getConfig().getBoolean("advertise.kick-player");
                advertise_warn = getConfig().getBoolean("advertise.warn-player");
                swear_kick_message = getConfig().getString("swear.kick-message");
                spam_kick_message = getConfig().getString("spam.kick-message");
                caps_kick_message = getConfig().getString("caps.kick-message");
                swear_warn_message = getConfig().getString("swear.warn-message");
                caps_warn_message = getConfig().getString("caps.warn-message");
                advertise_kick_message = getConfig().getString("advertise.kick-message");
                advertise_warn_message = getConfig().getString("advertise.warn-message");
                join_message = getConfig().getString("join-message");
                quit_message = getConfig().getString("quit-message");
            }
            spamlist = new HashMap<String, Long>();
            countlist = new HashMap<String, Integer>();
            this.log = new NukeChat();
            String pluginFolder = this.getDataFolder().getAbsolutePath();
            (new File(pluginFolder)).mkdirs();
            NukeChat.swearlist = new DataBase(new File(pluginFolder + File.separator + "swear.txt"));
            NukeChat.swearlist.load();
            Logger.getLogger("Minecraft").info("[NukeChat] Nuke's plugin is enabled!");
            getServer().getPluginManager().registerEvents(new NukeSpam(log), this);
            getServer().getPluginManager().registerEvents(new NukeSwear(log), this);
            getServer().getPluginManager().registerEvents(new NukeCaps(log), this);
            getServer().getPluginManager().registerEvents(new NukeJoinQuitMessage(log), this);
            getServer().getPluginManager().registerEvents(new NukeAdvertise(log), this);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("nc") || cmd.getName().equalsIgnoreCase("nukechat"))
            {
                if(sender.hasPermission("nukechat.command"))
                {
                    if(args.length == 0)
                    {
                        sender.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: Unknown command. Try /nc help.");            }
                    else
                    {
                        if(args[0].equalsIgnoreCase("add"))
                        {
                            if(sender.hasPermission("nukechat.addswear"))
                            {
                                String swearword = args[1];
                                swearlist.add(swearword);
                                swearlist.save();
                                sender.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: " + ChatColor.YELLOW + "Word " + swearword + " is added to the swear list.");
                            }
                        }
                        else if(args[0].equalsIgnoreCase("remove"))
                        {
                            if(sender.hasPermission("nukechat.removeswear"))
                            {
                                String swearword = args[1];
                                swearlist.remove(swearword);
                                swearlist.save();
                                sender.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: " + ChatColor.YELLOW + "Word " + swearword + " is removed from the swear list.");
                            }
                        }  
                        else if(args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help"))
                        {
                            if(sender.hasPermission("nukechat.help"))
                            {
                                sender.sendMessage(ChatColor.YELLOW + "====================" + ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]" + ChatColor.YELLOW + "====================");
                                sender.sendMessage(ChatColor.YELLOW + "Help command: /nc ? or /nc help");
                                sender.sendMessage(ChatColor.YELLOW + "Add swearword: /nc add swearword or /nukechat add swearword");
                                sender.sendMessage(ChatColor.YELLOW + "Remove swearword: /nc remove swearword or /nukechat remove swearword");
                                sender.sendMessage(ChatColor.YELLOW + "Reload Config.yml: /nc reload or /nukechat reload");
                            }
                        }
                        else if(args[0].equalsIgnoreCase("reload"))
                        {
                            if(sender.hasPermission("nukechat.reload"))
                            {
                                this.reloadConfig();
                                seconds_between_message = getConfig().getInt("seconds-between-message");
                                swear_kick = getConfig().getBoolean("swear.kick-player");
                                swear_warn = getConfig().getBoolean("swear.warn-player");
                                caps_kick = getConfig().getBoolean("caps.kick-player");
                                caps_warn = getConfig().getBoolean("caps.warn-player");
                                caps_reducemessage = getConfig().getBoolean("caps.reducemessage-player");
                                advertise_kick = getConfig().getBoolean("advertise.kick-player");
                                advertise_warn = getConfig().getBoolean("advertise.warn-player");
                                swear_kick_message = getConfig().getString("swear.kick-message");
                                caps_kick_message = getConfig().getString("caps.kick-message");
                                spam_kick_message = getConfig().getString("spam.kick-message");
                                swear_warn_message = getConfig().getString("swear.warn-message");
                                caps_warn_message = getConfig().getString("caps.warn-message");
                                advertise_kick_message = getConfig().getString("advertise.kick-message");
                                advertise_warn_message = getConfig().getString("advertise.warn-message");
                                join_message = getConfig().getString("join-message");
                                quit_message = getConfig().getString("quit-message");
                                sender.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: " + ChatColor.YELLOW + "Config.yml reloaded!");
                            }
                        }
                        else
                        {
                            sender.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: Unknown command. Try /nc help.");
                        }
                    }
                }
            }
            return true;
        }
    }
    NukeSwear.java:
    Code (Text):
    package com.chaoticunited;
     
    import java.util.Iterator;
    import java.util.List;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
     
    public class NukeSwear implements Listener
    {
        private NukeChat plugin;
        public NukeSwear(NukeChat plugin)
        {
            this.plugin = plugin;
        }
        @SuppressWarnings({ "unchecked", "static-access" })
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event)
        {
            if(!event.getPlayer().hasPermission("nukechat.freeswear"))
            {
                boolean answer = plugin.swear_kick;
                boolean answer2 = plugin.swear_warn;
                if(answer)
                {
                    Player p = event.getPlayer();
                    String playername = p.getName();
                    String message = event.getMessage();
                    String messagetwo = message.toLowerCase();
                    String kickmessage = plugin.swear_kick_message;
                    List swears = plugin.swearlist.getValues();
                    for(Iterator i$ = swears.iterator(); i$.hasNext();)
                    {
                        String e = (String)i$.next();
                        if(messagetwo.contains(e))
                        {
                            event.setCancelled(true);
                            p.kickPlayer(kickmessage);
                            Logger.getLogger("Minecraft").info("[NukeChat] Player " + playername + " was kicked for swearing.");
                            for(Player players: Bukkit.getServer().getOnlinePlayers())
                            {
                                if(players.hasPermission("nukechat.notify"))
                                {
                                    players.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]:" + ChatColor.YELLOW + " Player " + playername + " is kicked for swearing.");
                                }
                            }
                        break;
                        }
                    }
                }
                else if(answer2)
                {
                    List swears = plugin.swearlist.getValues();
                    for(Iterator i$ = swears.iterator(); i$.hasNext();)
                    {
                        Player p = event.getPlayer();
                        String playername = p.getName();
                        String message = event.getMessage();
                        String messagetwo = message.toLowerCase();
                        String e = (String)i$.next();
                        if(messagetwo.contains(e))
                        {
                            event.setCancelled(true);
                            String warnmessage = plugin.swear_warn_message;
                            p.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeChat" + ChatColor.RED + "]: " + warnmessage);
                            Logger.getLogger("Minecraft").info("[NukeChat] Player " + playername + " was warned for swearing.");
                            break;
                        }
                    }
                }
                else
                {
                    Logger.getLogger("Minecraft").info("[NukeChat] Both of swear-kick-player and swear-warn-player is false!");
                }
            }
        }
    }
    The null message is telling me that its this line:
    Code (Text):
    p.kickPlayer(kickmessage);
    By any chance, can someone give me an example of the code to kick the player and is supported by spigot. I know spigot blocked all api calls.
     
  4. Bestle

    Patron

    I have the same issue when kicking from a plugin, even though it's all sync.
     
  5. Code (Text):
    public class Kicker extends JavaPlugin
    {
        public String KickMsg= "┬žeBad Manors";
        onLoad()... etc...
    }
    //Sync Repeating Task//
    public void run() {
        player.kickPlayer(this.plugin.KickMsg);
    }
     
    Hmm. This works for me.
    Maybe you should add magical "this." ?
     
  6. Its not the message at all. This plugin works in craftbukkit but not in spigot...