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.command.Claim;
022import com.plotsquared.core.player.PlotPlayer;
023import com.plotsquared.core.plot.Plot;
024import com.plotsquared.core.plot.PlotArea;
025import org.checkerframework.checker.nullness.qual.Nullable;
026
027/**
028 * PlayerAutoPlotEvent returns null for {@link PlotEvent#getPlot()} as the event is fired before the plot is chosen.
029 */
030public class PlayerAutoPlotEvent extends PlotEvent implements CancellablePlotEvent {
031
032    private final PlotPlayer<?> player;
033    private final PlotArea plotArea;
034    private Result eventResult;
035    private String schematic;
036    private int sizeX;
037    private int sizeZ;
038
039    /**
040     * PlayerAutoPlotEvent: called when a player attempts to auto claim a plot.
041     *
042     * @param player    The player attempting to auto claim
043     * @param plotArea  The applicable plot area
044     * @param schematic The schematic defined or null
045     * @param sizeX     The size of the auto area
046     * @param sizeZ     The size of the auto area
047     */
048    public PlayerAutoPlotEvent(
049            PlotPlayer<?> player, PlotArea plotArea, @Nullable String schematic,
050            int sizeX, int sizeZ
051    ) {
052        super(null);
053        this.player = player;
054        this.plotArea = plotArea;
055        this.schematic = schematic;
056        this.sizeX = sizeX;
057        this.sizeZ = sizeZ;
058    }
059
060    /**
061     * Returns null as the plots to be claimed haven't been chosen yet. This will depend on the size of the auto
062     * ({@link PlayerAutoPlotEvent#setSizeX(int)} and {@link PlayerAutoPlotEvent#setSizeZ(int)}). To see which plots have been
063     * chosen, see {@link PlayerAutoPlotsChosenEvent}.
064     *
065     * @return null
066     */
067    @Override
068    public @Nullable Plot getPlot() {
069        return null;
070    }
071
072    /**
073     * Obtain the schematic string as used by the {@link Claim} command or null.
074     *
075     * @return schematic string
076     */
077    public @Nullable String getSchematic() {
078        return this.schematic;
079    }
080
081    /**
082     * Set the schematic string used in the claim.
083     *
084     * @param schematic the schematic name
085     */
086    public void setSchematic(String schematic) {
087        this.schematic = schematic;
088    }
089
090    @Override
091    public Result getEventResult() {
092        return eventResult;
093    }
094
095    @Override
096    public void setEventResult(Result e) {
097        this.eventResult = e;
098    }
099
100    public PlotPlayer<?> getPlayer() {
101        return this.player;
102    }
103
104    public PlotArea getPlotArea() {
105        return this.plotArea;
106    }
107
108    /**
109     * Get the x size of the auto-area
110     *
111     * @return x size
112     * @since 6.1.0
113     */
114    public int getSizeX() {
115        return this.sizeX;
116    }
117
118    /**
119     * Set the x size of the auto-area
120     *
121     * @param sizeX x size
122     * @since 6.1.0
123     */
124    public void setSizeX(int sizeX) {
125        this.sizeX = sizeX;
126    }
127
128    /**
129     * Get the z size of the auto-area
130     *
131     * @return z size
132     * @since 6.1.0
133     */
134    public int getSizeZ() {
135        return this.sizeZ;
136    }
137
138    /**
139     * Set the z size of the auto-area
140     *
141     * @param sizeZ z size
142     * @since 6.1.0
143     */
144    public void setSizeZ(int sizeZ) {
145        this.sizeZ = sizeZ;
146    }
147
148}