Skip to content
Ken Anderson edited this page Jul 20, 2013 · 5 revisions

This method queries the Minecraft WebSocketServer for offline player information.

Method Signature

The following is the method signature:

CaffeinatedRat.Minecraft.WebSocketServices.prototype.getOfflinePlayers(parameters)

Parameters

The following parameters are available for this method:

callback

This is a callback function that is called when the client-side library has successful received the offline player information.

  • Value: function(jsonDataStructure) { }
  • Default: Do nothing special.

Please refer to the Json data structure documented for the [OfflinePlayers] (https://github.com/CaffeinatedRat/WebSocketServices/wiki/OfflinePlayers-Service#json-response-format) service.

Example

The following is an example of how to use the method and its callback function.

function callback(json) {
	
	if (json.OfflinePlayers.length > 0) {
	
		for(var i = 0; i < json.OfflinePlayers.length; i++) {
			
			var offlinePlayerInfo = json.OfflinePlayers[i];
			
			console.log('Last Played: ' + offlinePlayerInfo.lastPlayed);
			console.log('Name: ' + offlinePlayerInfo.name);
			console.log('IsOperator: ' + offlinePlayerInfo.isOperator);
			
		}
		
	}
	
}

wss.getOfflinePlayers({

	callback: callback

});

Template Fields

The template fields feature allows a user to tag almost any HTML element with a class that will automatically be populated by the server information. If no element is tagged then the client-side library will ignore this field. Template fields do not require knowledge or use of javascript, just simply decorate an element with one of the following classes.

Parent Container Field

The parent container field is a class that decorates an element that will be a parent container for a collection of items, such as a list of players. Item fields MUST be within a parent container.

  • wssMinecraftOfflineList

Class Only Fields

These are template fields that only work as classes to an element.

  • wssTotalOfflinePlayers

List Item Template Field

The list item template field is a class that decorates an element that describes how an item will be displayed to the user. List item fields are then attached to elements or can stand-alone as content fields, that are populated with the details for a specific item. For example, the online time of a player. This template MUST be within a parent container.

  • wssListItemTemplate

Empty List Item Template Field

The empty list item template field is a class that decorates an element that describes what will be displayed if nothing is returned by the service. For example, if no players are online, then the content of the empty list item template is shown. This template MUST be within a parent container.

  • wssEmptyListTemplate

Item Fields
These are fields that can be used as a class to an element and/or can be used as stand-alone content. Item fields describe a property of an item, such as the name of player. To use a item field as stand-alone content, simply surround the field with a set of pounds signs (#), as shown #wssPlayerName#. These fields MUST be contained within a wssListItemTemplate container.

  • wssPlayerFace
  • wssPlayerIsOperator
  • wssPlayerName
  • wssPlayerEnvironment
  • wssPlayerOnlineTime

Conditional List Item Fields
These are item fields that work as conditional elements, where the element will only appear if one or the other condition is met. This will only work if the element is decorated with these template fields as classes. These fields MUST be contained within a wssListItemTemplate container.

  • wssPlayerIsOperator
  • wssPlayerIsNotOperator

Example

The following is an example of how to use the template fields.

<div class="playerContainer scrollContainer">
    <div class="wssMinecraftOfflineList">
		<div>
			<strong>Offline Players: </strong>
			<span id="wssTotalOfflinePlayers"></span>
		</div>
		<ul class="wssListItemTemplate">
            <li>
                <div class="playerElement">
                    <div class="inline">
                        <div class="wssPlayerIsOperator">
                            <div title="Moderator" class="tiles modTile"></div>
                        </div>
                        <div class="wssPlayerIsNotOperator">
                            <div title="Player" class="tiles playerTile"></div>
                        </div>
                    </div>
                    <div class="inline">
                        #wssPlayerFace#
                    </div>
                    <div class="inline">
                        <a class="playerName" href="#" data-name="#wssPlayerName#" data-environment="#wssPlayerEnvironment#" title="Click to view #wssPlayerName#'s skin">
                            <strong>
                                #wssPlayerName#
                            </strong>
                        </a>
                    </div>
                    <div class="inline">
                        (#wssPlayerOnlineTime#)
                    </div>
                </div>
            </li>
        </ul>
        <ul class="wssEmptyListTemplate">
            <li>
                No offline player info available.
            </li>
        </ul>
    </div>
</div>