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

net.raidstone.wgevents.events.RegionsLeftEvent Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package net.raidstone.wgevents.events;

import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
 * @author Weby & Anrza ([email protected])
 * @version 1.0.0
 * @since 2/24/19
 */
public class RegionsLeftEvent extends Event implements Cancellable {
 
	private static final HandlerList handlers = new HandlerList();

	private boolean cancelled=false;
	
	private final UUID uuid;
	private final Set regions;
	private final Set regionsNames;

	/**
     * This even is fired whenever one or several regions are left.
     * @param playerUUID The UUID of the player leaving the regions.
     * @param regions Set of WorldGuard's ProtectedRegion regions.
     */
	public RegionsLeftEvent(UUID playerUUID, @Nullable Set regions)
	{
		this.uuid = playerUUID;
		this.regionsNames = new HashSet<>();
		this.regions = new HashSet<>();
		
		if (regions != null) {
			this.regions.addAll(regions);
			for (ProtectedRegion region : regions) {
				this.regionsNames.add(region.getId());
			}
		}
	}

	@Contract (pure = true)
	public static HandlerList getHandlerList() {
		return handlers;
	}
	
	@NotNull
	public HandlerList getHandlers() {
		return handlers;
	}
	
	@NotNull
	public UUID getUUID() {
		return uuid;
	}

	@Nullable
	public Player getPlayer() {
		return Bukkit.getPlayer(uuid);
	}
	
	@NotNull
	public Set getRegions() {
		return regions;
	}
	
	@NotNull
	public Set getRegionsNames() {
		return regionsNames;
	}
	
	@Override
	public boolean isCancelled() {
		return this.cancelled;
	}
	
	@Override
	public void setCancelled(boolean cancelled) {
		this.cancelled=cancelled;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy