NullPointerException for permissions

Discussion in 'Plugin Development' started by FoxinatorDev, Apr 16, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    FoxinatorDev

    Whenever I add a new permission to a rank, I want all the players who have that rank who are online rn have their permissions updated instead of relogging but when I tried, it's giving me an error. I'm certain I didn't code the updating right.

    Add Permission CMD:
    Code:
     if(args.length == 1 || args.length == 2) {
                                sender.sendMessage(ChatUtils.format("&cUsage: /permissions add <rank> <permission>\n" +
                                        "&cRanks: " + Arrays.asList(Rank.values()).toString().replace("[", "").replace("]", "")));
                                return true;
                            } else {
                                Rank rank = Rank.valueOf(args[1].toUpperCase());
                                String permission = args[2];
    
                                try {
                                    List<String> perms = new ArrayList<>(Arrays.asList(sql.getRankPermissions(rank)));
                                    List<String> bp = new ArrayList<>();
                                    for(String pm : perms) {
                                        bp.add(pm.trim());
                                    }
                                    p.sendMessage(perms.toString() + "\n" +
                                            bp.toString());
                                    if(bp.contains(permission)) {
                                        sender.sendMessage(ChatUtils.format("&e" + permission + "&c permission already exists!"));
                                        return true;
                                    } else {
                                        bp.add(permission);
                                    }
                                    sql.setRankPermissions(rank, bp);
                                    sender.sendMessage(ChatUtils.format("&aAdded the permission &e" + permission + "&a to " + RankUtils.getRankPrefix(rank) + "&a."));
                                } catch (Exception e) {
                                    sender.sendMessage(ChatUtils.format("&c(Error) Usage: /permissions add <rank> <permission>\n" +
                                            "&cRanks: " + Rank.values().toString().replace("[", "").replace("]", "")));
                                    e.printStackTrace();
                                }
    
    
                            }
    setRankPermisisons METHOD:
    Code:
       public void setRankPermissions(Rank rank, List<String> permissions) {
            try {
                List<String> bp = new ArrayList<>();
                PreparedStatement statement = Main.getConnection().prepareStatement("UPDATE " + Main.permstable + " SET PERMISSIONS=? WHERE RANK=?");
                for(String p : permissions) {
                    bp.add(p.trim());
                }
                statement.setString(1, permissions.toString().replace("[", "").replace("]", "").trim());
                statement.setString(2, rank.toString());
                statement.executeUpdate();
                for(Player p : Bukkit.getServer().getOnlinePlayers()) {
                    PermissionUtils.permissionsSetter(p.getUniqueId());
                }
            } catch(SQLException e) {
                e.printStackTrace();
            }
        }
    And this is the error I get. I don't even get what line the error is on.
    Code:
    [17:23:47 WARN]: java.lang.NullPointerException
     
  2. Offline

    timtower Ninja on the waves Moderator

Thread Status:
Not open for further replies.

Share This Page