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 org.checkerframework.checker.index.qual.NonNegative; 023import org.checkerframework.checker.nullness.qual.NonNull; 024 025/** 026 * Called every time after PlotSquared calculated a players plot limit based on their permission. 027 * <p> 028 * May be used to grant a player more plots based on another rank or bought feature. 029 * 030 * @since 7.3.0 031 */ 032public class PlayerPlotLimitEvent { 033 034 private final PlotPlayer<?> player; 035 036 private int limit; 037 038 public PlayerPlotLimitEvent(@NonNull final PlotPlayer<?> player, @NonNegative final int limit) { 039 this.player = player; 040 this.limit = limit; 041 } 042 043 /** 044 * Overrides the previously calculated or set plot limit for {@link #player()}. 045 * 046 * @param limit The amount of plots a player may claim. Must be {@code 0} or greater. 047 * @since 7.3.0 048 */ 049 public void limit(@NonNegative final int limit) { 050 if (limit < 0) { 051 throw new IllegalArgumentException("Player plot limit must be greater or equal 0"); 052 } 053 this.limit = limit; 054 } 055 056 /** 057 * Returns the previous set limit, if none was overridden before this event handler the default limit based on the players 058 * permissions node is returned. 059 * 060 * @return The currently defined plot limit of this player. 061 * @since 7.3.0 062 */ 063 public @NonNegative int limit() { 064 return limit; 065 } 066 067 /** 068 * The player for which the limit is queried. 069 * 070 * @return the player. 071 * @since 7.3.0 072 */ 073 public @NonNull PlotPlayer<?> player() { 074 return player; 075 } 076 077}