Skip to content

Optimized queue system for HUBs in Minecraft Networks

Notifications You must be signed in to change notification settings

Alejandro12120/kQueue

Repository files navigation

kQueue

Optimized queue system for HUBs in Minecraft Networks.

This queue system uses a simply linked list to store the data, so it is more efficient when there is a lot of players in the queue, or the queue is modified frequently.

This system is a basic one, since it doesn't have priorities for ranks, it only follows FIFO priority.

image

Usage

TestQueue

import es.alejandro12120.kqueue.servers.ServerQueue;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

@Getter
public class TestQueue {

    private final ServerQueue serverQueue;
    private boolean paused;
    private final long delay;

    public TestQueue() {
        this.serverQueue = new ServerQueue("test");
        this.paused = false;
        this.delay = 7; // In seconds

        startTask();
    }

    public void pauseQueue() {
        this.paused = true;
    }

    public void resumeQueue() {
        this.paused = false;
    }

    public void startTask() {
        new BukkitRunnable() {
            @Override
            public void run() {
                if (serverQueue.isQueueEmpty()) return;

                serverQueue.getPlayers().forEach(p -> p.sendMessage("Position: " + serverQueue.getPosition(p) + "/" + serverQueue.getQueueSize()));

                if (paused) return;

                Player player = serverQueue.removePlayerFromQueue();
                if (player != null)
                    player.sendMessage("You have been removed from the queue");
            }
        }.runTaskTimer(QueueSystem.getInstance(), 0, delay * 20);

    }
}

Add player to Queue:

#.getTestQueue().getServerQueue().addPlayerToQueue(player);

Remove player from Queue:

#.getTestQueue().getServerQueue().removePlayerFromQueue(); - Returns the player removed from the queue

Installation

Maven

Using a system dependency. Create a folder called libs in the root of your project and add the jar file to it.

<dependency>
    <groupId>es.alejandro12120</groupId>
    <artifactId>kQueue</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/kqueue.jar</systemPath>
</dependency>

About

Optimized queue system for HUBs in Minecraft Networks

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages