Someone please tell my why this won't ban offline players!

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 24, 2017.

  1. I was working on a code that I have and it won't ban offline players. Can you please help me so I can make it so it ban offline players.
    Code (Text):
     else if(cmd.getName().equalsIgnoreCase("ban")) {
            String PName1 = args[0];
            final Player target1 = Bukkit.getPlayerExact(PName1);
            if(!sender.hasPermission("minegrid.ban")) {
                sender.sendMessage(ChatColor.RED + "Requested Permission Level \n MODERATOR");
            }
            if(sender.hasPermission("minegrid.ban")) {
                if(!(args.length > 1)) {
                    sender.sendMessage(ChatColor.RED + "Usage, /ban (player) (reason)");
                }
                if(args.length > 1) {
                        StringBuilder message1 = new StringBuilder();

                        for (int i = 1; i < args.length; i++) {
                            message1.append(args[i] + " ");
                        }
                       
                            target1.kickPlayer(ChatColor.WHITE + "Internal Exception: java.io.IOException: An existing connection was forcibly closed by remote host");
                            getConfig().set("banned." + target1.getUniqueId() + ".reason", message1.toString());
                            getConfig().set("banned." + target1.getUniqueId() + ".issuer", sender.getName());
                            saveConfig();
                            sender.sendMessage(ChatColor.RED + "You have permanently banned, " + target1.getName() + " for, " + message1);
                            Bukkit.broadcast(ChatColor.RED + sender.getName() + " has permanently banned " + target1.getName() + " for " + message1, "minegrid.notify");
                } if(target1 == null) {
                    OfflinePlayer targetoffline = Bukkit.getOfflinePlayer(args[0]);
                    StringBuilder message1 = new StringBuilder();

                    for (int i = 1; i < args.length; i++) {
                        message1.append(args[i] + " ");
                    }
                        getConfig().set("banned." + targetoffline.getUniqueId() + ".reason", message1.toString());
                        getConfig().set("banned." + targetoffline.getUniqueId() + ".issuer", sender.getName());
                        saveConfig();
                        sender.sendMessage(ChatColor.RED + "You have permanently banned, " + targetoffline.getName() + " for, " + message1);
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has permanently banned " + targetoffline.getName() + " for " + message1, "minegrid.notify");
                }
            }
        }
     
  2. did the player joined before?
    second you may just ban the name if the player is not existed and on their join kick them if their name is in banlist?
     
  3. I'm currently working on a plugin called xPunish with another developer so I got this all figured out. You want to make a separate config file for each player and check if it exists on join. If a file exists named with their UUID, it will kick them and send them to strings from the config file. No code for you.
     
  4. I tried to do what you said but I am stuck here and I have a few errors and I don't know what they mean
    Code (Text):
        @EventHandler
        public void LogOnBanned(final AsyncPlayerPreLoginEvent e) {
            UUID p = e.getUniqueId();
            if(getConfig().getString("banned." + p) == null) {
            e.allow();
            } else {
                String reason2 = getConfig().getString("banned." + p + ".reason");
                String issuer2 = getConfig().getString("banned." + p + ".issuer");
                e.disallow(Result.KICK_BANNED, ChatColor.RED + "Kicked whilst connecting: you are currently banned" + "\n"
                        + "\n"
                        + ChatColor.RED + "Banned by, " + issuer2 + "\n"
                        + ChatColor.RED + "Reason, " + reason2);
            }
        }
       
        @EventHandler
        public void PlayerInfo(final PlayerJoinEvent e) {
            Player p = e.getPlayer();
            String test1 = getConfig().getString("playerinfo." + p.getUniqueId() != null);
            if(test1 != null) {
                saveConfig();
            }
            if(test1 == null) {
                getConfig().set("playerinfo." + p.getUniqueId(), arg1);
            }
        }
     
  5. We won't know either until you post the error log in console.
     
    • Agree Agree x 1
  6. It says I have an error at getString in this String test1 = getConfig().getString("playerinfo." + p.getUniqueId() != null);
     
  7. *sigh*
    Code (Text):
    p.getUniqueId().toString()
    If you can't fix a simple thing then don't even bother making plugins. Sorry, but even I could do that when I was a noob.
     
  8. ummm it is not a string it is a boolean.
     
  9. You may want to consider storing players, or accessing player data files in the world files. These store all necessary player information (name, unique ID, etc).