@ SuppressWarnings ( "unchecked" ) public ApiBuddy execute ( ) { User sfsOwner = api . getUserByName ( owner ) ; ApiUser targetUser = getUser ( target ) ; ApiUser ownerUser = ( ApiUser ) sfsOwner . getProperty ( APIKey . USER ) ; ISFSBuddyResponseApi responseAPI = SmartFoxServer . getInstance ( ) . getAPIManager ( ) . getBuddyApi ( ) . getResponseAPI ( ) ; ISFSEventManager eventManager = SmartFoxServer . getInstance ( ) . getEventManager ( ) ; BuddyList buddyList = sfsOwner . getZone ( ) . getBuddyListManager ( ) . getBuddyList ( owner ) ; BuddyListManager buddyListManager = sfsOwner . getZone ( ) . getBuddyListManager ( ) ; checkBuddyManagerIsActive ( buddyListManager , sfsOwner ) ; sfsOwner . updateLastRequestTime ( ) ; ApiBuddyImpl buddy = new ApiBuddyImpl ( target , temp ) ; buddy . setOwner ( ownerUser ) ; buddy . setParentBuddyList ( buddyList ) ; if ( targetUser != null ) buddy . setUser ( targetUser ) ; try { buddyList . addBuddy ( buddy ) ; if ( fireClientEvent ) responseAPI . notifyAddBuddy ( buddy , sfsOwner ) ; if ( fireServerEvent ) { Map < ISFSEventParam , Object > evtParams = new HashMap <> ( ) ; evtParams . put ( SFSEventParam . ZONE , sfsOwner . getZone ( ) ) ; evtParams . put ( SFSEventParam . USER , sfsOwner ) ; evtParams . put ( SFSBuddyEventParam . BUDDY , buddy ) ; eventManager . dispatchEvent ( new SFSEvent ( SFSEventType . BUDDY_ADD , evtParams ) ) ; } } catch ( SFSBuddyListException e ) { if ( fireClientEvent ) { api . getResponseAPI ( ) . notifyRequestError ( e , sfsOwner , SystemRequest . AddBuddy ) ; } return null ; } return buddy ; }
Execute to add a buddy to list