Plan API

Feb 22, 2017
Plan API
  • Plan API v.2.0.0

    Player Analytics API can be used to integrate the Web features of Plan to any other Web Server Admin panel that is using Java and allows addition of html.

    Importing Plan API:
    To import Plan API you need following imports:

    Code (Text):
    main.java.com.djrapitops.plan.Plan

    main.java.com.djrapitops.plan.api.API
    (and possibly):
    main.java.com.djrapitops.plan.data.UserData
    main.java.com.djrapitops.plan.data.AnalysisData


    To get access to the API's methods:
    Code (Text):
    API api = getPlugin(Plan.class).getAPI();
    API offers following methods:
    Code (Text):


        /**
         * Uses UUIDFetcher to turn PlayerName to UUID
         *
         * @param playerName Player's name
         * @return UUID of the Player
         * @throws Exception if player's name is not registered at Mojang
         */
        public UUID playerNameToUUID(String playerName) throws Exception {
            return UUIDFetcher.getUUIDOf(playerName);
        }

        /**
         * Caches the UserData to the InspectCache for time specified in the Plan
         * config, so it can be called by webserver.
         *
         * Does not cache anything if the player has not joined the server or has no
         * data in the database.
         *
         * @param uuid UUID of the Player
         */
        public void cacheUserDataToInspectCache(UUID uuid) {
            plugin.getInspectCache().cache(uuid);
        }

        /**
         * Returns the ip:port/player/playername html as a string so it can be
         * integrated into other webserver plugins.
         *
         * If UserData of the specified player is not in the Cache returns <h1>404
         * Data was not found in cache</h1>
         *
         * @param uuid UUID of the Player
         * @return html as a string or a single error line html.
         */
        public String getPlayerHtmlAsString(UUID uuid) {
            return plugin.getUiServer().getDataReqHandler().getDataHtml(uuid);
        }

        /**
         * Updates the AnalysisCache so the cached data can be called by the
         * webserver.
         */
        public void updateAnalysisCache() {
            plugin.getAnalysisCache().updateCache();
        }

        /**
         * Returns the ip:port/server html as a string so it can be integrated into
         * other webserver plugins.
         *
         * If AnalysisData is not in the AnalysisCache: returns <h1>404 Data was not
         * found in cache</h1>
         *
         * @return html as a string or a single error line html.
         */
        public String getAnalysisHtmlAsString() {
            return plugin.getUiServer().getDataReqHandler().getAnalysisHtml();
        }

        /**
         * Returns UserData from the InspectCache
         *
         * @param uuid UUID of the Player
         * @return UserData of the Player in the InspectCache or null if not found
         */
        public UserData getUserDataFromInspectCache(UUID uuid) {
            return plugin.getInspectCache().getFromCache(uuid);
        }

        /**
         * Returns AnalysisData from the AnalysisCache
         * @return AnalysisData in the AnalysisCache or null if not found
         */
        public AnalysisData getAnalysisDataFromCache() {
            return plugin.getAnalysisCache().getData();
        }

    Integrating to existing html
    To view Plan's data on the browser, the data must first be cached.
    For this purpose there are:
    public void cacheUserDataToInspectCache(UUID uuid)
    and
    public void updateAnalysisCache()

    After calling corresponding cache to be updated you can use
    public String getPlayerHtmlAsString(UUID uuid)
    and
    public String getAnalysisHtmlAsString().
    Please note that these Strings come with <html>, <head> & <body> tags (also end tags) that should be removed with .replaceAll if your html does has them
    You can view the html files inside the Plan.jar - player.html and analysis.html.
  • Loading...
  • Loading...