Coder Social home page Coder Social logo

queueapi's Introduction

QueueAPI

This is an API to easily create queues for Spigot servers.

Usage

  1. Install the api to your local maven repo using maven install
  2. Add this dependency to your Spigot plugin and set the scope to compile.
<dependency>
    <groupId>com.quadflame</groupId>
    <artifactId>QueueAPI</artifactId>
    <version>1.0.0</version>
    <scope>compile</scope>
</dependency>

Example

Create your own queue for players using the PlayerQueue class.

// Create a queue using Bukkit Players
QueueAPI.createQueue(new PlayerQueue("MyQueue", 1, 2, new QueueAction<Player>() {
    @Override
    public void onJoin(Player player) {
        player.sendMessage(ChatColor.GREEN + "You joined the queue!");
    }

    @Override
    public void onLeave(Player player) {
        player.sendMessage(ChatColor.RED + "You left the queue!");
    }

    @Override
    public void onFill(List<Team<Player>> teams) {
        int teamCounter = 0;
        for (Team<Player> team : teams) {
            for (Player player : team.getMembers()) {
                player.sendMessage(ChatColor.YELLOW + "You are in team: " + teamCounter);
            }
            teamCounter++;
        }
    }
}));

// Get a PlayerQueue
PlayerQueue playerQueue = QueueAPI.getPlayerQueue("MyQueue");

// Add a player to a queue (Returns true if the player was added)
QueueAPI.getPlayerQueue("MyQueue").join(player);

// Remove a player from a queue (Returns true if the player was removed)
QueueAPI.getPlayerQueue("MyQueue").remove(player);

// Delete a queue to prevent players from joining it
QueueAPI.deleteQueue("MyQueue");

// Get any type of queue
AbstractQueue<?> otherQueue = QueueAPI.getQueue("OtherQueue");

Or even create queues for a specific object eg. UUID and have full control of storing your own queues.

public class TestQueue extends AbstractQueue<UUID> {
    @Override
    public String getName() {
        return "TestQueue";
    }

    @Override
    public int getTeamSize() {
        return 4;
    }

    @Override
    public int getTeamCount() {
        return 2;
    }

    @Override
    public void onJoin(UUID uuid) {
        Bukkit.getPlayer(uuid).sendMessage(ChatColor.GREEN + "You joined the queue!");
    }

    @Override
    public void onLeave(UUID uuid) {
        Bukkit.getPlayer(uuid).sendMessage(ChatColor.RED + "You left the queue!");
    }

    @Override
    public void onFill(List<Team<UUID>> teams) {
        int teamCounter = 0;
        for (Team<UUID> team : teams) {
            for (UUID uuid : team.getMembers()) {
                Bukkit.getPlayer(uuid).sendMessage(ChatColor.YELLOW + "You are in team: " + teamCounter);
            }
            teamCounter++;
        }
    }
}

Alternatively, this has the same functionality as the previous example:

QueueAPI.createQueue(new AbstractQueue.Builder<UUID>()
        // Set the name of the queue
        .name("myQueue")
        // Set the number of teams
        .teamCount(2)
        // Set the size of each team
        .teamSize(4)
        // Set the action to be executed when something happens to the queue
        .queueAction(new QueueAction<UUID>() {  
            // This is called when a player joins the queue
            @Override
            public void onJoin(UUID uuid) {
                Bukkit.getPlayer(uuid).sendMessage(ChatColor.GREEN + "You joined the queue!");
            }   
            // This is called when a player leaves the queue
            @Override
            public void onLeave(UUID uuid) {
                Bukkit.getPlayer(uuid).sendMessage(ChatColor.RED + "You left the queue!");
            }   
            // This is called when the queue is full
            @Override
            public void onFill(List<Team<UUID>> teams) {
                int teamCounter = 0;
                for (Team<UUID> team : teams) {
                    for (UUID uuid : team.getMembers()) {
                        Bukkit.getPlayer(uuid).sendMessage(ChatColor.YELLOW + "You are in team: " + teamCounter);
                    }
                    teamCounter++;
                }
            }
        }).build());

queueapi's People

Stargazers

 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.