Example usage for org.json JSONObject isNull

List of usage examples for org.json JSONObject isNull

Introduction

In this page you can find the example usage for org.json JSONObject isNull.

Prototype

public boolean isNull(String key) 

Source Link

Document

Determine if the value associated with the key is null or if there is no value.

Usage

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

private Section createSectionFromJSON(JSONObject o) {
    Section s = new Section();

    s.setName(o.getString("name"));
    s.setId(o.getInt("id"));

    if (!o.isNull("parent_id")) {
        s.setParentId(String.valueOf(o.getInt("parent_id")));
    } else {//from   ww w .  ja  va  2  s  . c om
        s.setParentId("null");
    }

    s.setSuiteId(o.getInt("suite_id"));

    return s;
}

From source file:net.dv8tion.jda.core.handle.VoiceStateUpdateHandler.java

private void handleGuildVoiceState(JSONObject content) {
    final long userId = content.getLong("user_id");
    final long guildId = content.getLong("guild_id");
    final Long channelId = !content.isNull("channel_id") ? content.getLong("channel_id") : null;
    final String sessionId = !content.isNull("session_id") ? content.getString("session_id") : null;
    boolean selfMuted = content.getBoolean("self_mute");
    boolean selfDeafened = content.getBoolean("self_deaf");
    boolean guildMuted = content.getBoolean("mute");
    boolean guildDeafened = content.getBoolean("deaf");
    boolean suppressed = content.getBoolean("suppress");

    Guild guild = api.getGuildById(guildId);
    if (guild == null) {
        api.getEventCache().cache(EventCache.Type.GUILD, guildId, () -> handle(responseNumber, allContent));
        EventCache.LOG/* ww  w  .  ja  v  a 2  s.c o  m*/
                .debug("Received a VOICE_STATE_UPDATE for a Guild that has yet to be cached. JSON: " + content);
        return;
    }

    VoiceChannelImpl channel = channelId != null ? (VoiceChannelImpl) guild.getVoiceChannelById(channelId)
            : null;
    if (channel == null && channelId != null) {
        api.getEventCache().cache(EventCache.Type.CHANNEL, channelId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug(
                "Received VOICE_STATE_UPDATE for a VoiceChannel that has yet to be cached. JSON: " + content);
        return;
    }

    MemberImpl member = (MemberImpl) guild.getMemberById(userId);
    if (member == null) {
        //Caching of this might not be valid. It is possible that we received this
        // update due to this Member leaving the guild while still connected to a voice channel.
        // In that case, we should not cache this because it could cause problems if they rejoined.
        //However, we can't just ignore it completely because it could be a user that joined off of
        // an invite to a VoiceChannel, so the GUILD_MEMBER_ADD and the VOICE_STATE_UPDATE may have
        // come out of order. Not quite sure what to do. Going to cache for now however.
        //At the worst, this will just cause a few events to fire with bad data if the member rejoins the guild if
        // in fact the issue was that the VOICE_STATE_UPDATE was sent after they had left, however, by caching
        // it we will preserve the integrity of the cache in the event that it was actually a mis-ordering of
        // GUILD_MEMBER_ADD and VOICE_STATE_UPDATE. I'll take some bad-data events over an invalid cache.
        api.getEventCache().cache(EventCache.Type.USER, userId, () -> handle(responseNumber, allContent));
        EventCache.LOG
                .debug("Received VOICE_STATE_UPDATE for a Member that has yet to be cached. JSON: " + content);
        return;
    }

    GuildVoiceStateImpl vState = (GuildVoiceStateImpl) member.getVoiceState();
    vState.setSessionId(sessionId); //Cant really see a reason for an event for this

    if (!Objects.equals(channel, vState.getChannel())) {
        VoiceChannelImpl oldChannel = (VoiceChannelImpl) vState.getChannel();
        vState.setConnectedChannel(channel);

        if (oldChannel == null) {
            channel.getConnectedMembersMap().put(userId, member);
            api.getEventManager().handle(new GuildVoiceJoinEvent(api, responseNumber, member));
        } else if (channel == null) {
            oldChannel.getConnectedMembersMap().remove(userId);
            api.getEventManager().handle(new GuildVoiceLeaveEvent(api, responseNumber, member, oldChannel));
        } else {
            //If the connect account is the one that is being moved, and this instance of JDA
            // is connected or attempting to connect, them change the channel we expect to be connected to.
            if (guild.getSelfMember().equals(member)) {
                AudioManagerImpl mng = api.getAudioManagerMap().get(guildId);
                if (mng != null && (mng.isConnected() || mng.isAttemptingToConnect()))
                    mng.setConnectedChannel(channel);
            }

            channel.getConnectedMembersMap().put(userId, member);
            oldChannel.getConnectedMembersMap().remove(userId);
            api.getEventManager().handle(new GuildVoiceMoveEvent(api, responseNumber, member, oldChannel));
        }
    }

    boolean wasMute = vState.isMuted();
    boolean wasDeaf = vState.isDeafened();

    if (selfMuted != vState.isSelfMuted()) {
        vState.setSelfMuted(selfMuted);
        api.getEventManager().handle(new GuildVoiceSelfMuteEvent(api, responseNumber, member));
    }
    if (selfDeafened != vState.isSelfDeafened()) {
        vState.setSelfDeafened(selfDeafened);
        api.getEventManager().handle(new GuildVoiceSelfDeafenEvent(api, responseNumber, member));
    }
    if (guildMuted != vState.isGuildMuted()) {
        vState.setGuildMuted(guildMuted);
        api.getEventManager().handle(new GuildVoiceGuildMuteEvent(api, responseNumber, member));
    }
    if (guildDeafened != vState.isGuildDeafened()) {
        vState.setGuildDeafened(guildDeafened);
        api.getEventManager().handle(new GuildVoiceGuildDeafenEvent(api, responseNumber, member));
    }
    if (suppressed != vState.isSuppressed()) {
        vState.setSuppressed(suppressed);
        api.getEventManager().handle(new GuildVoiceSuppressEvent(api, responseNumber, member));
    }
    if (wasMute != vState.isMuted())
        api.getEventManager().handle(new GuildVoiceMuteEvent(api, responseNumber, member));
    if (wasDeaf != vState.isDeafened())
        api.getEventManager().handle(new GuildVoiceDeafenEvent(api, responseNumber, member));
}

From source file:net.dv8tion.jda.core.handle.VoiceStateUpdateHandler.java

private void handleCallVoiceState(JSONObject content) {
    final long userId = content.getLong("user_id");
    final Long channelId = !content.isNull("channel_id") ? content.getLong("channel_id") : null;
    String sessionId = !content.isNull("session_id") ? content.getString("session_id") : null;
    boolean selfMuted = content.getBoolean("self_mute");
    boolean selfDeafened = content.getBoolean("self_deaf");

    //Joining a call
    CallableChannel channel;/*from  w  ww. ja  v a2s.c o m*/
    CallVoiceStateImpl vState;
    if (channelId != null) {
        channel = api.asClient().getGroupById(channelId);
        if (channel == null)
            channel = api.getPrivateChannelMap().get(channelId);

        if (channel == null) {
            api.getEventCache().cache(EventCache.Type.CHANNEL, channelId,
                    () -> handle(responseNumber, allContent));
            EventCache.LOG.debug(
                    "Received a VOICE_STATE_UPDATE for a Group/PrivateChannel that was not yet cached! JSON: "
                            + content);
            return;
        }

        CallImpl call = (CallImpl) channel.getCurrentCall();
        if (call == null) {
            api.getEventCache().cache(EventCache.Type.CALL, channelId,
                    () -> handle(responseNumber, allContent));
            EventCache.LOG
                    .debug("Received a VOICE_STATE_UPDATE for a Call that is not yet cached. JSON: " + content);
            return;
        }

        CallUser cUser = ((JDAClientImpl) api.asClient()).getCallUserMap().get(userId);
        if (cUser != null && channelId != cUser.getCall().getCallableChannel().getIdLong()) {
            WebSocketClient.LOG.fatal(
                    "Received a VOICE_STATE_UPDATE for a user joining a call, but the user was already in a different call! Big error! JSON: "
                            + content);
            ((CallVoiceStateImpl) cUser.getVoiceState()).setInCall(false);
        }

        cUser = call.getCallUserMap().get(userId);
        if (cUser == null) {
            api.getEventCache().cache(EventCache.Type.USER, userId, () -> handle(responseNumber, allContent));
            EventCache.LOG.debug(
                    "Received a VOICE_STATE_UPDATE for a user that is not yet a a cached CallUser for the call. (groups only). JSON: "
                            + content);
            return;
        }

        ((JDAClientImpl) api.asClient()).getCallUserMap().put(userId, cUser);
        vState = (CallVoiceStateImpl) cUser.getVoiceState();
        vState.setSessionId(sessionId);
        vState.setInCall(true);

        api.getEventManager().handle(new CallVoiceJoinEvent(api, responseNumber, cUser));
    } else //Leaving a call
    {
        CallUser cUser = ((JDAClientImpl) api.asClient()).getCallUserMap().remove(userId);
        if (cUser == null) {
            api.getEventCache().cache(EventCache.Type.USER, userId, () -> handle(responseNumber, allContent));
            EventCache.LOG.debug(
                    "Received a VOICE_STATE_UPDATE for a User leaving a Call, but the Call was not yet cached! JSON: "
                            + content);
            return;
        }

        Call call = cUser.getCall();
        channel = call.getCallableChannel();
        vState = (CallVoiceStateImpl) cUser.getVoiceState();
        vState.setSessionId(sessionId);
        vState.setInCall(false);

        api.getEventManager().handle(new CallVoiceLeaveEvent(api, responseNumber, cUser));
    }

    //Now that we're done dealing with the joins and leaves, we can deal with the mute/deaf changes.
    if (selfMuted != vState.isSelfMuted()) {
        vState.setSelfMuted(selfMuted);
        api.getEventManager().handle(new CallVoiceSelfMuteEvent(api, responseNumber, vState.getCallUser()));
    }
    if (selfDeafened != vState.isSelfDeafened()) {
        vState.setSelfDeafened(selfDeafened);
        api.getEventManager().handle(new CallVoiceSelfDeafenEvent(api, responseNumber, vState.getCallUser()));
    }
}

From source file:CNCServicesServlet.CNCServices.java

/**
 * Demo Call Buy Card Service/*from  w w w . ja v a 2  s .  c  o  m*/
 */
private String BuyCard(HttpServletRequest request) {
    String txtData = "";
    String txtAgentCode = request.getServletContext().getInitParameter("agentCode");
    String txtAgentKey = request.getServletContext().getInitParameter("agentKey");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 7);
    Date date = cal.getTime();
    SimpleDateFormat ft = new SimpleDateFormat("YYYYMMddhhmmssss");
    BuyCardRequest bcr = new BuyCardRequest(txtAgentCode, "VT", ft.format(date).toString(), 10000, 2);
    String bcrString = bcr.toString();
    ResponseRequest rr = new ResponseRequest();
    try {
        txtData = Util.Encrypt(txtAgentKey, bcrString);
        Softpin soft = new Softpin();
        String result = soft.getSoftpinSoap12().buyCard(txtAgentCode, txtData);
        JSONObject jsonObject = new JSONObject(result);
        String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg");
        rr.setMsg(msg);
        String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid");
        rr.setTranid(tranid);
        String listCards = jsonObject.isNull("listCards") ? "" : jsonObject.getString("listCards");
        Integer code = jsonObject.getInt("code");
        rr.setCode(code);
        if (code == 1) {
            String listResult = Util.Decrypt(txtAgentKey, listCards);
            rr.setListCards(listResult);
            System.out.println("success");
        } else {
            rr.setListCards("");
            System.out.println("Error=" + msg);
        }
    } catch (Exception e) {
        rr.setListCards("");
        System.out.println("error=" + e.getMessage());
    }
    return rr.toString();
}

From source file:CNCServicesServlet.CNCServices.java

/**
 * Demo Call Get Card Service/* w  ww  .ja  v a 2s.  c  o  m*/
 */
private String GetCard(HttpServletRequest request) {
    String txtData = "";
    String txtAgentCode = request.getServletContext().getInitParameter("agentCode");
    String txtAgentKey = request.getServletContext().getInitParameter("agentKey");
    String tranidRequest = "2016062711420056";
    GetCardRequest gcr = new GetCardRequest(txtAgentCode, tranidRequest);
    String gcrString = gcr.toString();
    ResponseRequest rr = new ResponseRequest();
    try {
        txtData = Util.Encrypt(txtAgentKey, gcrString);
        Softpin soft = new Softpin();
        String result = soft.getSoftpinSoap12().getCard(txtAgentCode, txtData);
        JSONObject jsonObject = new JSONObject(result);
        String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg");
        rr.setMsg(msg);
        String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid");
        rr.setTranid(tranid);
        String listCards = jsonObject.isNull("listCards") ? "" : jsonObject.getString("listCards");
        Integer code = jsonObject.getInt("code");
        rr.setCode(code);
        if (code == 1) {
            String listResult = Util.Decrypt(txtAgentKey, listCards);
            rr.setListCards(listResult);
            System.out.println("success");
        } else {
            rr.setListCards("");
            System.out.println("Error=" + msg);
        }
    } catch (Exception e) {
        rr.setListCards("");
        System.out.println("error=" + e.getMessage());
    }
    return rr.toString();
}

From source file:CNCServicesServlet.CNCServices.java

/**
 * Demo Call Topup Serivce//  ww  w. j  a v  a  2 s.c  o m
 */
private String Topup(HttpServletRequest request) {
    String txtData = "";
    String txtAgentCode = request.getServletContext().getInitParameter("agentCode");
    String txtAgentKey = request.getServletContext().getInitParameter("agentKey");
    String tranidRequest = "2016062711420056";
    TopupRequest tr = new TopupRequest(txtAgentCode, "VT", tranidRequest, "0902183903", 10000, "VTT");
    String trString = tr.toString();
    ResponseTopup rt = new ResponseTopup();
    try {
        txtData = Util.Encrypt(txtAgentKey, trString);
        Softpin soft = new Softpin();
        String result = soft.getSoftpinSoap12().topup(txtAgentCode, txtData);
        JSONObject jsonObject = new JSONObject(result);
        String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg");
        rt.setMsg(msg);
        String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid");
        rt.setTranid(tranid);
        Integer code = jsonObject.getInt("code");
        rt.setCode(code);
    } catch (Exception e) {
        System.out.println("error=" + e.getMessage());
    }
    return rt.toString();
}

From source file:CNCServicesServlet.CNCServices.java

/**
 * Demo Call Check Transaction Topup Service
 *//*  w w  w. j a v  a2  s  .com*/
private String CheckTranTopup(HttpServletRequest request) {
    String txtData = "";
    String txtAgentCode = request.getServletContext().getInitParameter("agentCode");
    String txtAgentKey = request.getServletContext().getInitParameter("agentKey");
    String tranidRequest = "2016062711420056";
    GetCardRequest gcr = new GetCardRequest(txtAgentCode, tranidRequest);
    String gcrString = gcr.toString();
    ResponseTopup rt = new ResponseTopup();
    try {
        txtData = Util.Encrypt(txtAgentKey, gcrString);
        Softpin soft = new Softpin();
        String result = soft.getSoftpinSoap12().checkTranTopup(txtAgentCode, txtData);
        JSONObject jsonObject = new JSONObject(result);
        String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg");
        rt.setMsg(msg);
        String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid");
        rt.setTranid(tranid);
        Integer code = jsonObject.getInt("code");
        rt.setCode(code);
    } catch (Exception e) {
        System.out.println("error=" + e.getMessage());
    }
    return rt.toString();
}

From source file:CNCServicesServlet.CNCServices.java

/**
 * Demo Call Check Count Service/* w  w w  . j a  v  a  2  s.  c o  m*/
 */
private String CheckCount(HttpServletRequest request) {
    String txtData = "";
    String txtAgentCode = request.getServletContext().getInitParameter("agentCode");
    String txtAgentKey = request.getServletContext().getInitParameter("agentKey");
    CheckCountRequest ccrequest = new CheckCountRequest(txtAgentCode, "VT", 10000);
    String ccRequestString = ccrequest.toString();
    CheckCountResponse ccResponse = new CheckCountResponse();
    try {
        txtData = Util.Encrypt(txtAgentKey, ccRequestString);
        Softpin soft = new Softpin();
        String result = soft.getSoftpinSoap12().checkCount(txtAgentCode, txtData);
        JSONObject jsonObject = new JSONObject(result);
        String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg");
        ccResponse.setMsg(msg);
        String listprovider = jsonObject.isNull("listprovider") ? "" : jsonObject.getString("listprovider");
        Integer code = jsonObject.getInt("code");
        ccResponse.setCode(code);
        if (code == 1) {
            String listResult = Util.Decrypt(txtAgentKey, listprovider);
            ccResponse.setListprovider(listResult);
            System.out.println("success");
        } else {
            ccResponse.setListprovider("");
            System.out.println("Error=" + msg);
        }
    } catch (Exception e) {
        ccResponse.setListprovider("");
        System.out.println("error=" + e.getMessage());
    }
    return ccResponse.toString();
}

From source file:hongik.android.project.best.StoreReviewActivity.java

public void drawTable() throws Exception {
    String query = "func=morereview" + "&license=" + license;
    DBConnector conn = new DBConnector(query);
    conn.start();/*w ww .  ja v  a  2 s. co m*/

    conn.join();
    JSONObject jsonResult = conn.getResult();
    boolean result = jsonResult.getBoolean("result");

    if (!result) {
        return;
    }

    String storeName = jsonResult.getString("sname");
    ((TextViewPlus) findViewById(R.id.storereview_storename)).setText(storeName);

    JSONArray review = null;
    if (!jsonResult.isNull("review")) {
        review = jsonResult.getJSONArray("review");
    }

    //Draw Review Table
    if (review != null) {
        TableRow motive = (TableRow) reviewTable.getChildAt(1);

        for (int i = 0; i < review.length(); i++) {
            JSONObject json = review.getJSONObject(i);
            final String[] elements = new String[4];
            elements[0] = Double.parseDouble(json.getString("GRADE")) + "";
            elements[1] = json.getString("NOTE");
            elements[2] = json.getString("CID#");
            elements[3] = json.getString("DAY");

            TableRow tbRow = new TableRow(this);
            TextViewPlus[] tbCols = new TextViewPlus[4];

            if (elements[1].length() > 14)
                elements[1] = elements[1].substring(0, 14) + "...";

            for (int j = 0; j < 4; j++) {
                tbCols[j] = new TextViewPlus(this);
                tbCols[j].setText(elements[j]);
                tbCols[j].setLayoutParams(motive.getChildAt(j).getLayoutParams());
                tbCols[j].setGravity(Gravity.CENTER);
                tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(),
                        "InterparkGothicBold.ttf"));
                tbCols[j].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent reviewIntent = new Intent(originActivity, ReviewDetailActivity.class);
                        reviewIntent.putExtra("ACCESS", "STORE");
                        reviewIntent.putExtra("CID", elements[2]);
                        reviewIntent.putExtra("LICENSE", license);
                        Log.i("StoreReview", "StartActivity");
                        startActivity(reviewIntent);
                    }
                });

                Log.i("StoreMenu", "COL" + j + ":" + elements[j]);
                tbRow.addView(tbCols[j]);
            }
            reviewTable.addView(tbRow);
        }
    }
    reviewTable.removeViewAt(1);
}

From source file:net.dv8tion.jda.core.handle.PresenceUpdateHandler.java

@Override
protected Long handleInternally(JSONObject content) {
    //Do a pre-check to see if this is for a Guild, and if it is, if the guild is currently locked.
    if (content.has("guild_id")) {
        final long guildId = content.getLong("guild_id");
        if (api.getGuildLock().isLocked(guildId))
            return guildId;
    }//from   ww w.j av  a 2  s . c o  m

    JSONObject jsonUser = content.getJSONObject("user");
    final long userId = jsonUser.getLong("id");
    UserImpl user = (UserImpl) api.getUserMap().get(userId);

    //If we do know about the user, lets update the user's specific info.
    // Afterwards, we will see if we already have them cached in the specific guild
    // or Relation. If not, we'll cache the OnlineStatus and Game for later handling
    // unless OnlineStatus is OFFLINE, in which case we probably received this event
    // due to a User leaving a guild or no longer being a relation.
    if (user != null) {
        if (jsonUser.has("username")) {
            String name = jsonUser.getString("username");
            String discriminator = jsonUser.get("discriminator").toString();
            String avatarId = jsonUser.isNull("avatar") ? null : jsonUser.getString("avatar");

            if (!user.getName().equals(name)) {
                String oldUsername = user.getName();
                String oldDiscriminator = user.getDiscriminator();
                user.setName(name);
                user.setDiscriminator(discriminator);
                api.getEventManager().handle(
                        new UserNameUpdateEvent(api, responseNumber, user, oldUsername, oldDiscriminator));
            }
            String oldAvatar = user.getAvatarId();
            if (!(avatarId == null && oldAvatar == null) && !Objects.equals(avatarId, oldAvatar)) {
                String oldAvatarId = user.getAvatarId();
                user.setAvatarId(avatarId);
                api.getEventManager().handle(new UserAvatarUpdateEvent(api, responseNumber, user, oldAvatarId));
            }
        }

        //Now that we've update the User's info, lets see if we need to set the specific Presence information.
        // This is stored in the Member or Relation objects.
        String gameName = null;
        String gameUrl = null;
        Game.GameType type = null;
        if (!content.isNull("game") && !content.getJSONObject("game").isNull("name")) {
            gameName = content.getJSONObject("game").get("name").toString();
            gameUrl = (content.getJSONObject("game").isNull("url") ? null
                    : content.getJSONObject("game").get("url").toString());
            try {
                type = content.getJSONObject("game").isNull("type") ? Game.GameType.DEFAULT
                        : Game.GameType.fromKey(
                                Integer.parseInt(content.getJSONObject("game").get("type").toString()));
            } catch (NumberFormatException ex) {
                type = Game.GameType.DEFAULT;
            }
        }
        Game nextGame = (gameName == null ? null : new GameImpl(gameName, gameUrl, type));
        OnlineStatus status = OnlineStatus.fromKey(content.getString("status"));

        //If we are in a Guild, then we will use Member.
        // If we aren't we'll be dealing with the Relation system.
        if (content.has("guild_id")) {
            GuildImpl guild = (GuildImpl) api.getGuildById(content.getLong("guild_id"));
            MemberImpl member = (MemberImpl) guild.getMember(user);

            //If the Member is null, then User isn't in the Guild.
            //This is either because this PRESENCE_UPDATE was received before the GUILD_MEMBER_ADD event
            // or because a Member recently left and this PRESENCE_UPDATE came after the GUILD_MEMBER_REMOVE event.
            //If it is because a Member recently left, then the status should be OFFLINE. As such, we will ignore
            // the event if this is the case. If the status isn't OFFLINE, we will cache and use it when the
            // Member object is setup during GUILD_MEMBER_ADD
            if (member == null) {
                //Cache the presence and return to finish up.
                if (status != OnlineStatus.OFFLINE) {
                    guild.getCachedPresenceMap().put(userId, content);
                    return null;
                }
            } else {
                //The member is already cached, so modify the presence values and fire events as needed.
                if (!member.getOnlineStatus().equals(status)) {
                    OnlineStatus oldStatus = member.getOnlineStatus();
                    member.setOnlineStatus(status);
                    api.getEventManager().handle(
                            new UserOnlineStatusUpdateEvent(api, responseNumber, user, guild, oldStatus));
                }
                if (member.getGame() == null ? nextGame != null : !member.getGame().equals(nextGame)) {
                    Game oldGame = member.getGame();
                    member.setGame(nextGame);
                    api.getEventManager()
                            .handle(new UserGameUpdateEvent(api, responseNumber, user, guild, oldGame));
                }
            }
        } else {
            //In this case, this PRESENCE_UPDATE is for a Relation.

        }
    } else {
        //In this case, we don't have the User cached, which means that we can't update the User's information.
        // This is most likely because this PRESENCE_UPDATE came before the GUILD_MEMBER_ADD that would have added
        // this User to our User cache. Or, it could have come after a GUILD_MEMBER_REMOVE that caused the User
        // to be removed from JDA's central User cache because there were no more connected Guilds. If this is
        // the case, then the OnlineStatus will be OFFLINE and we can ignore this event.
        //Either way, we don't have the User cached so we need to cache the Presence information if
        // the OnlineStatus is not OFFLINE.

        //If the OnlineStatus is OFFLINE, ignore the event and return.
        OnlineStatus status = OnlineStatus.fromKey(content.getString("status"));
        if (status == OnlineStatus.OFFLINE)
            return null;

        //If this was for a Guild, cache it in the Guild for later use in GUILD_MEMBER_ADD
        if (content.has("guild_id")) {
            GuildImpl guild = (GuildImpl) api.getGuildById(content.getLong("guild_id"));
            guild.getCachedPresenceMap().put(userId, content);
        } else {
            //cache in relationship stuff
        }
    }
    return null;
}