File tree Expand file tree Collapse file tree 3 files changed +68
-1
lines changed
Core/src/main/java/com/plotsquared/core Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Original file line number Diff line number Diff line change
1
+ package com .plotsquared .core .events ;
2
+
3
+ import com .plotsquared .core .player .PlotPlayer ;
4
+ import org .checkerframework .checker .index .qual .NonNegative ;
5
+ import org .checkerframework .checker .nullness .qual .NonNull ;
6
+
7
+ /**
8
+ * Called every time after PlotSquared calculated a players plot limit based on their permission.
9
+ * <p>
10
+ * May be used to grant a player more plots based on another rank or bought feature.
11
+ *
12
+ * @since TODO
13
+ */
14
+ public class PlayerPlotLimitEvent {
15
+
16
+ private final PlotPlayer <?> player ;
17
+
18
+ private int limit ;
19
+
20
+ public PlayerPlotLimitEvent (@ NonNull final PlotPlayer <?> player , @ NonNegative final int limit ) {
21
+ this .player = player ;
22
+ this .limit = limit ;
23
+ }
24
+
25
+ /**
26
+ * Overrides the previously calculated or set plot limit for {@link #player()}.
27
+ *
28
+ * @param limit The amount of plots a player may claim. Must be {@code 0} or greater.
29
+ * @since TODO
30
+ */
31
+ public void setLimit (@ NonNegative final int limit ) {
32
+ if (limit < 0 ) {
33
+ throw new IllegalArgumentException ("Player plot limit must be greater or equal 0" );
34
+ }
35
+ this .limit = limit ;
36
+ }
37
+
38
+ /**
39
+ * Returns the previous set limit, if none was overridden before this event handler the default limit based on the players
40
+ * permissions node is returned.
41
+ *
42
+ * @return The currently defined plot limit of this player.
43
+ * @since TODO
44
+ */
45
+ public @ NonNegative int limit () {
46
+ return limit ;
47
+ }
48
+
49
+ /**
50
+ * The player for which the limit is queried.
51
+ *
52
+ * @return the player.
53
+ * @since TODO
54
+ */
55
+ public @ NonNull PlotPlayer <?> player () {
56
+ return player ;
57
+ }
58
+
59
+ }
Original file line number Diff line number Diff line change @@ -306,7 +306,8 @@ public Plot getCurrentPlot() {
306
306
* @return number of allowed plots within the scope (globally, or in the player's current world as defined in the settings.yml)
307
307
*/
308
308
public int getAllowedPlots () {
309
- return hasPermissionRange ("plots.plot" , Settings .Limit .MAX_PLOTS );
309
+ final int calculatedLimit = hasPermissionRange ("plots.plot" , Settings .Limit .MAX_PLOTS );
310
+ return this .eventDispatcher .callPlayerPlotLimit (this , calculatedLimit ).limit ();
310
311
}
311
312
312
313
/**
Original file line number Diff line number Diff line change 30
30
import com .plotsquared .core .events .PlayerLeavePlotEvent ;
31
31
import com .plotsquared .core .events .PlayerPlotDeniedEvent ;
32
32
import com .plotsquared .core .events .PlayerPlotHelperEvent ;
33
+ import com .plotsquared .core .events .PlayerPlotLimitEvent ;
33
34
import com .plotsquared .core .events .PlayerPlotTrustedEvent ;
34
35
import com .plotsquared .core .events .PlayerTeleportToPlotEvent ;
35
36
import com .plotsquared .core .events .PlotAutoMergeEvent ;
@@ -308,6 +309,12 @@ public RemoveRoadEntityEvent callRemoveRoadEntity(Entity entity) {
308
309
return event ;
309
310
}
310
311
312
+ public PlayerPlotLimitEvent callPlayerPlotLimit (PlotPlayer <?> player , int calculatedLimit ) {
313
+ PlayerPlotLimitEvent event = new PlayerPlotLimitEvent (player , calculatedLimit );
314
+ eventBus .post (event );
315
+ return event ;
316
+ }
317
+
311
318
public void doJoinTask (final PlotPlayer <?> player ) {
312
319
if (player == null ) {
313
320
return ; //possible future warning message to figure out where we are retrieving null
You can’t perform that action at this time.
0 commit comments