All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dailystruggle.rtp.common.tasks.ForceQueue Maven / Gradle / Ivy

The newest version!
package io.github.dailystruggle.rtp.common.tasks;

import io.github.dailystruggle.commandsapi.common.CommandsAPI;
import io.github.dailystruggle.rtp.common.RTP;
import io.github.dailystruggle.rtp.common.selection.region.Region;
import io.github.dailystruggle.rtp.common.serverSide.substitutions.RTPCommandSender;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public final class ForceQueue extends RTPRunnable {
    public static final List> preActions = new ArrayList<>();
    public static final List> postActions = new ArrayList<>();
    private final RTPCommandSender sender;
    private final Collection regions;

    public ForceQueue() {
        sender = RTP.serverAccessor.getSender(CommandsAPI.serverId);
        regions = RTP.selectionAPI.permRegionLookup.values();
    }

    public ForceQueue(RTPCommandSender sender) {
        this.sender = sender;
        regions = RTP.selectionAPI.permRegionLookup.values();
    }

    public ForceQueue(RTPCommandSender sender,
                      @Nullable Collection regions) {
        this.sender = sender;
        if (regions == null || regions.size() == 0) regions = RTP.selectionAPI.permRegionLookup.values();
        this.regions = regions;
    }

    @Override
    public void run() {
        preActions.forEach(consumer -> consumer.accept(this));

        for (Region region : regions) {
            region.execute(Long.MAX_VALUE);
        }

        postActions.forEach(consumer -> consumer.accept(this));
    }

    public RTPCommandSender sender() {
        return sender;
    }

    public Collection regions() {
        return regions;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        ForceQueue that = (ForceQueue) obj;
        return Objects.equals(this.sender, that.sender) &&
                Objects.equals(this.regions, that.regions);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sender, regions);
    }

    @Override
    public String toString() {
        return "DoTeleport[" +
                "sender=" + sender + ", " +
                "regions=" + regions + ']';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy