Giter Site home page Giter Site logo

jstatsapi's Introduction

JStatsAPI

A simple API for creating custom statistics in Minecraft.

Features

  • Create custom statistics
  • Database and file storage
  • Easily implementable into any plugin

Usage

Using JStatsAPI was designed to be as simple as possible. There are only a few steps to creating a statistic.

Creating a Provider

This is a required step as many functions in the API require a provider to be passed in. The first argument is the plugin instance, and the second is whether other plugins can change the value of the statistics provided by this provider. 9 times out of 10, you will want to set this to false.

public final class Main extends JavaPlugin {
    @Override
    public void onEnable() {
        JStatProvider provider = new JStatProvider(this, false);
    }
}

Creating a Statistic

The first argument is the name of the statistic, the second is the provider, the third is the ID of the statistic, and the fourth is the default value of the statistic. JStat accepts any class that extends Number (e.g. Integer, Double, Float, etc.)

public final class Main extends JavaPlugin {
    @Override
    public void onEnable() {
        JStatProvider provider = new JStatProvider(this);
        
        JStatsAPI.getInstance().registerStat(
                new JStat<>(
                        "Test Stat",
                        provider,
                        "test-stat",
                        0
                )
        );
    }
}

Getting a Statistic

In order to get a statistic, you must first create a StatRequest object. This object takes two arguments: the provider, and the ID of the statistic. This then gets passed into the JStatsAPI.makeRequest() method, which returns a JStat object. If the statistic does not exist, null will be returned.

In order to change the value, you must pass the UUID of the player you want to change the value for.

import java.util.UUID;

public final class Main extends JavaPlugin {
    @Override
    public void onEnable() {
        JStatProvider provider = new JStatProvider(this);

        JStat<Integer> testStat = new JStat<>(
                "Test Stat",
                provider,
                "test-stat",
                0
        );

        JStatsAPI.getInstance().registerStat(testStat);

        incrementTestStat(UUID.randomUUID());
    }

    public void incrementTestStat(UUID uuid) {
        JStat<Integer> stat = JStatsAPI.getInstance().makeRequest(
                StatRequest(
                        provider,
                        "test-stat"
                )
        );

        if (stat != null) {
            stat.addValueFor(uuid, 1);
        }
    }
}

jstatsapi's People

Contributors

jcurtis06 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.