001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.events; 020 021import com.plotsquared.core.player.PlotPlayer; 022import com.plotsquared.core.plot.Plot; 023import org.checkerframework.checker.nullness.qual.NonNull; 024import org.checkerframework.checker.nullness.qual.Nullable; 025 026import java.util.Collections; 027import java.util.List; 028 029/** 030 * Event fired when the plots that are to be claimed by a player executing a /plot auto have been chosen. It contains an 031 * unmodifiable list of the plots selected. This may be of length 0. This event is effectively cancellable by setting the list 032 * of plots to an empty list. 033 */ 034public class PlayerAutoPlotsChosenEvent extends PlotPlayerEvent { 035 036 private List<Plot> plots; 037 038 /** 039 * PlayerAutoPlotsChosenEvent: Called when one or more plots are chosen for a /plot auto 040 * 041 * @param player Player that executed the auto 042 * @param plots Plots that have been chosen to be set to the player 043 * @since 6.1.0 044 */ 045 public PlayerAutoPlotsChosenEvent(PlotPlayer<?> player, List<Plot> plots) { 046 super(player, plots.size() > 0 ? plots.get(0) : null); 047 this.plots = Collections.unmodifiableList(plots); 048 } 049 050 /** 051 * Returns the plot at index 0 in the list of plots selected. May be null if the list was of length 0. 052 * 053 * @return plot at index 0 or null. 054 */ 055 @Override 056 public @Nullable Plot getPlot() { 057 return super.getPlot(); 058 } 059 060 /** 061 * Get the immutable list of plots selected to be claimed by the player. May be of length 0. 062 * 063 * @return immutable list. 064 * @since 6.1.0 065 */ 066 public @NonNull List<Plot> getPlots() { 067 return plots; 068 } 069 070 /** 071 * Set the plots to be claimed by the player. 072 * 073 * @param plots list of plots. 074 * @since 6.1.0 075 */ 076 public void setPlots(final @NonNull List<Plot> plots) { 077 this.plots = List.copyOf(plots); 078 } 079 080}