PlotSquared/Core/src/main/java/com/plotsquared/core/util/Permissions.java

149 lines
6.9 KiB
Java
Raw Normal View History

/*
* 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/>.
*/
2020-04-15 21:26:54 +02:00
package com.plotsquared.core.util;
2020-04-16 06:14:33 +02:00
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.permissions.Permission;
2020-07-22 12:35:48 +02:00
import com.plotsquared.core.permissions.PermissionHolder;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.player.PlotPlayer;
import net.kyori.adventure.text.minimessage.Template;
import org.checkerframework.checker.nullness.qual.NonNull;
2016-03-21 00:35:40 +01:00
2015-12-19 20:30:06 +01:00
/**
* The Permissions class handles checking user permissions.<br>
2018-08-10 17:01:10 +02:00
* - This will respect * nodes and plots.admin and can be used to check permission ranges (e.g. plots.plot.5)<br>
* - Checking the PlotPlayer class directly will not take the above into account<br>
*
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes
2015-12-19 20:30:06 +01:00
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
2015-09-13 06:04:31 +02:00
public class Permissions {
2016-11-30 06:07:16 +01:00
/**
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PlotPlayer#hasPermission(String, boolean)}
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
public static boolean hasPermission(PlotPlayer<?> player, Permission permission, boolean notify) {
return hasPermission(player, permission.toString(), notify);
2016-11-30 06:07:16 +01:00
}
2015-12-19 20:30:06 +01:00
/**
2020-07-24 12:44:04 +02:00
* Check if the owner of the profile has a given (global) permission
2018-08-10 17:01:10 +02:00
*
* @param caller permission holder
2020-07-24 12:44:04 +02:00
* @param permission Permission
* @return {@code true} if the owner has the given permission, else {@code false}
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PermissionHolder#hasPermission(Permission)}
2015-12-19 20:30:06 +01:00
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
public static boolean hasPermission(final @NonNull PermissionHolder caller, final @NonNull Permission permission) {
2020-07-24 17:44:47 +02:00
return caller.hasPermission(permission.toString());
2015-07-13 19:42:02 +02:00
}
2018-08-10 17:01:10 +02:00
2015-12-19 20:30:06 +01:00
/**
* Check if the owner of the profile has a given (global) permission. There is no guarantee that per-world permissions will
* be checked because unmaintained crap plugins like PEX exist.
2018-08-10 17:01:10 +02:00
*
* @param caller permission holder
2020-07-24 12:44:04 +02:00
* @param permission Permission
* @return {@code true} if the owner has the given permission, else {@code false}
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PermissionHolder#hasPermission(String)}
2015-12-19 20:30:06 +01:00
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
public static boolean hasPermission(final @NonNull PermissionHolder caller, final @NonNull String permission) {
2020-07-24 12:44:04 +02:00
return caller.hasPermission(permission);
}
2018-08-10 17:01:10 +02:00
/**
* Check if the owner of the profile has a given (global) keyed permission. Checks both {@code permission.key}
* and {@code permission.*}
*
* @param caller permission holder
* @param permission Permission
* @param key Permission "key"
* @return {@code true} if the owner has the given permission, else {@code false}
* @since 6.0.10
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PermissionHolder#hasKeyedPermission(String, String)}
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
public static boolean hasKeyedPermission(
final @NonNull PermissionHolder caller, final @NonNull String permission,
final @NonNull String key
) {
return caller.hasKeyedPermission(permission, key);
}
2015-12-19 20:30:06 +01:00
/**
2019-12-07 03:16:09 +01:00
* Checks if a PlotPlayer has a permission, and optionally send the no permission message if applicable.
2018-08-10 17:01:10 +02:00
*
* @param player permission holder
* @param permission permission
* @param notify if to notify the permission holder
* @return if permission is had
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PlotPlayer#hasPermission(String, boolean)}
2015-12-19 20:30:06 +01:00
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
2020-07-22 12:35:48 +02:00
public static boolean hasPermission(PlotPlayer<?> player, String permission, boolean notify) {
2016-03-23 02:41:37 +01:00
if (!hasPermission(player, permission)) {
2015-09-13 06:04:31 +02:00
if (notify) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", permission)
);
}
2015-08-11 15:42:46 +02:00
return false;
}
2015-08-11 15:42:46 +02:00
return true;
}
/**
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PlotPlayer#hasPermissionRange(Permission, int)}
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
public static int hasPermissionRange(PlotPlayer<?> player, Permission Permission, int range) {
return hasPermissionRange(player, Permission.toString(), range);
}
2015-12-19 20:30:06 +01:00
/**
2020-10-09 20:50:12 +02:00
* Check the highest permission a PlotPlayer has within a specified range.<br>
2018-08-10 17:01:10 +02:00
* - Excessively high values will lag<br>
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
*
2020-07-22 12:35:48 +02:00
* @param player Player to check for
2018-08-10 17:01:10 +02:00
* @param stub The permission stub to check e.g. for `plots.plot.#` the stub is `plots.plot`
* @param range The range to check
2015-12-19 20:30:06 +01:00
* @return The highest permission they have within that range
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
* classes. Use {@link PlotPlayer#hasPermissionRange(String, int)}
2015-12-19 20:30:06 +01:00
*/
2022-07-25 21:10:39 +02:00
@Deprecated(forRemoval = true, since = "6.9.3")
2020-07-22 12:35:48 +02:00
public static int hasPermissionRange(PlotPlayer<?> player, String stub, int range) {
2018-05-17 09:46:54 +02:00
return player.hasPermissionRange(stub, range);
}
}