-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cancelable event results are nullable * chore: add javadocs to CancellablePlotEvent# * feat: events for plot buy process
- Loading branch information
1 parent
ae941e6
commit 951f08b
Showing
6 changed files
with
212 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Core/src/main/java/com/plotsquared/core/events/PlayerBuyPlotEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* PlotSquared, a land and world management plugin for Minecraft. | ||
* Copyright (C) IntellectualSites <https://intellectualsites.com> | ||
* Copyright (C) IntellectualSites team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.plotsquared.core.events; | ||
|
||
import com.plotsquared.core.player.PlotPlayer; | ||
import com.plotsquared.core.plot.Plot; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Called when a user attempts to buy a plot. | ||
* <p> | ||
* Setting the {@link #setEventResult(Result) Result} to {@link Result#FORCE} ignores the price and players account balance and does not charge the | ||
* player anything. {@link Result#DENY} blocks the purchase completely, {@link Result#ACCEPT} and {@code null} do not modify | ||
* the behaviour. | ||
* <p> | ||
* Setting the {@link #setPrice(double) price} to {@code 0} makes the plot practically free. | ||
* | ||
* @since TODO | ||
*/ | ||
public class PlayerBuyPlotEvent extends PlotPlayerEvent implements CancellablePlotEvent { | ||
|
||
private Result result; | ||
private double price; | ||
|
||
public PlayerBuyPlotEvent(final PlotPlayer<?> plotPlayer, final Plot plot, @NonNegative final double price) { | ||
super(plotPlayer, plot); | ||
this.price = price; | ||
} | ||
|
||
|
||
/** | ||
* Sets the price required to buy the plot. | ||
* | ||
* @param price the new price. | ||
* @since TODO | ||
*/ | ||
public void setPrice(@NonNegative final double price) { | ||
//noinspection ConstantValue - the annotation does not ensure a non-negative runtime value | ||
if (price < 0) { | ||
throw new IllegalArgumentException("price must be non-negative"); | ||
} | ||
this.price = price; | ||
} | ||
|
||
/** | ||
* Returns the currently set price required to buy the plot. | ||
* | ||
* @return the price. | ||
* @since TODO | ||
*/ | ||
public @NonNegative double price() { | ||
return price; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void setEventResult(@Nullable final Result eventResult) { | ||
this.result = eventResult; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public @Nullable Result getEventResult() { | ||
return this.result; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
Core/src/main/java/com/plotsquared/core/events/post/PostPlayerBuyPlotEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* PlotSquared, a land and world management plugin for Minecraft. | ||
* Copyright (C) IntellectualSites <https://intellectualsites.com> | ||
* Copyright (C) IntellectualSites team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.plotsquared.core.events.post; | ||
|
||
import com.plotsquared.core.events.PlotPlayerEvent; | ||
import com.plotsquared.core.player.OfflinePlotPlayer; | ||
import com.plotsquared.core.player.PlotPlayer; | ||
import com.plotsquared.core.plot.Plot; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
|
||
/** | ||
* Called after a player has successfully bought a plot. | ||
* | ||
* @since TODO | ||
*/ | ||
public class PostPlayerBuyPlotEvent extends PlotPlayerEvent { | ||
|
||
private final OfflinePlotPlayer previousOwner; | ||
private final double price; | ||
|
||
public PostPlayerBuyPlotEvent( | ||
final PlotPlayer<?> plotPlayer, final OfflinePlotPlayer previousOwner, final Plot plot, | ||
@NonNegative final double price | ||
) { | ||
super(plotPlayer, plot); | ||
this.previousOwner = previousOwner; | ||
this.price = price; | ||
} | ||
|
||
/** | ||
* The previous owner of the bought plot. | ||
* | ||
* @return the previous owner. | ||
*/ | ||
public OfflinePlotPlayer previousOwner() { | ||
return previousOwner; | ||
} | ||
|
||
/** | ||
* Returns the price after potential modifications by {@link com.plotsquared.core.events.PlayerBuyPlotEvent}. | ||
* | ||
* @return the price the player had to pay to buy the plot. | ||
*/ | ||
public double price() { | ||
return price; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters