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 com.plotsquared.core.plot.PlotId;
024import org.checkerframework.checker.nullness.qual.Nullable;
025
026import java.util.UUID;
027
028public class PlotChangeOwnerEvent extends PlotEvent implements CancellablePlotEvent {
029
030    private final PlotPlayer<?> initiator;
031    @Nullable
032    private final UUID oldOwner;
033    private final boolean hasOldOwner;
034    @Nullable
035    private UUID newOwner;
036    private Result eventResult;
037
038    /**
039     * PlotChangeOwnerEvent: Called when a plot's owner is change.
040     *
041     * @param initiator   The player attempting to set the plot's owner
042     * @param plot        The plot having its owner changed
043     * @param oldOwner    The old owner of the plot or null
044     * @param newOwner    The new owner of the plot or null
045     * @param hasOldOwner If the plot has an old owner
046     */
047    public PlotChangeOwnerEvent(
048            PlotPlayer<?> initiator, Plot plot, @Nullable UUID oldOwner,
049            @Nullable UUID newOwner, boolean hasOldOwner
050    ) {
051        super(plot);
052        this.initiator = initiator;
053        this.newOwner = newOwner;
054        this.oldOwner = oldOwner;
055        this.hasOldOwner = hasOldOwner;
056    }
057
058    /**
059     * Get the PlotId.
060     *
061     * @return PlotId
062     */
063    public PlotId getPlotId() {
064        return getPlot().getId();
065    }
066
067    /**
068     * Get the world name.
069     *
070     * @return String
071     */
072    public String getWorld() {
073        return getPlot().getWorldName();
074    }
075
076    /**
077     * Get the change-owner initiator
078     *
079     * @return Player
080     */
081    public PlotPlayer<?> getInitiator() {
082        return this.initiator;
083    }
084
085    /**
086     * Get the old owner of the plot. Null if not exists.
087     *
088     * @return UUID
089     */
090    public @Nullable UUID getOldOwner() {
091        return this.oldOwner;
092    }
093
094    /**
095     * Get the new owner of the plot
096     *
097     * @return UUID
098     */
099    public @Nullable UUID getNewOwner() {
100        return this.newOwner;
101    }
102
103
104    /**
105     * Set the new owner of the plot. Null for no owner.
106     *
107     * @param newOwner the new owner or null
108     */
109    public void setNewOwner(@Nullable UUID newOwner) {
110        this.newOwner = newOwner;
111    }
112
113    /**
114     * Get if the plot had an old owner
115     *
116     * @return boolean
117     */
118    public boolean hasOldOwner() {
119        return this.hasOldOwner;
120    }
121
122    @Override
123    public Result getEventResult() {
124        return eventResult;
125    }
126
127    @Override
128    public void setEventResult(Result e) {
129        this.eventResult = e;
130    }
131
132}