2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.util;
|
2015-07-09 16:20:19 +02:00
|
|
|
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-07-22 19:42:22 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2021-01-09 22:28:41 +01:00
|
|
|
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;
|
2020-07-22 19:42:22 +02:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-01-09 22:28:41 +01:00
|
|
|
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>
|
2022-07-24 15:55:43 +02:00
|
|
|
*
|
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* 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
|
|
|
|
2022-07-24 15:55:43 +02:00
|
|
|
/**
|
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* classes. Use {@link PlotPlayer#hasPermission(String, boolean)}
|
2022-07-24 15:55:43 +02:00
|
|
|
*/
|
2022-07-25 21:10:39 +02:00
|
|
|
@Deprecated(forRemoval = true, since = "6.9.3")
|
2020-08-07 12:53:32 +02:00
|
|
|
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
|
|
|
*
|
2021-01-09 22:28:41 +01: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}
|
2022-07-24 15:55:43 +02:00
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* 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")
|
2021-01-09 22:28:41 +01:00
|
|
|
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
|
|
|
/**
|
2022-07-24 15:55:43 +02: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
|
|
|
*
|
2021-01-09 22:28:41 +01: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}
|
2022-07-24 15:55:43 +02:00
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* 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")
|
2021-01-09 22:28:41 +01:00
|
|
|
public static boolean hasPermission(final @NonNull PermissionHolder caller, final @NonNull String permission) {
|
2020-07-24 12:44:04 +02:00
|
|
|
return caller.hasPermission(permission);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2021-08-14 15:13:01 +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}
|
2022-01-24 21:46:01 +01:00
|
|
|
* @since 6.0.10
|
2022-07-24 15:55:43 +02:00
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* classes. Use {@link PermissionHolder#hasKeyedPermission(String, String)}
|
2021-08-14 15:13:01 +02:00
|
|
|
*/
|
2022-07-25 21:10:39 +02:00
|
|
|
@Deprecated(forRemoval = true, since = "6.9.3")
|
2021-08-14 15:13:01 +02:00
|
|
|
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
|
|
|
*
|
2021-01-09 22:28:41 +01:00
|
|
|
* @param player permission holder
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param permission permission
|
2021-01-09 22:28:41 +01:00
|
|
|
* @param notify if to notify the permission holder
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return if permission is had
|
2022-07-24 15:55:43 +02:00
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* 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) {
|
2020-07-22 19:42:22 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("permission.no_permission_event"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("node", permission)
|
2020-07-22 19:42:22 +02:00
|
|
|
);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-08-11 15:42:46 +02:00
|
|
|
return false;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-08-11 15:42:46 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2016-09-26 10:31:08 +02:00
|
|
|
|
2022-07-24 15:55:43 +02:00
|
|
|
/**
|
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* classes. Use {@link PlotPlayer#hasPermissionRange(Permission, int)}
|
2022-07-24 15:55:43 +02:00
|
|
|
*/
|
2022-07-25 21:10:39 +02:00
|
|
|
@Deprecated(forRemoval = true, since = "6.9.3")
|
2020-08-07 12:53:32 +02:00
|
|
|
public static int hasPermissionRange(PlotPlayer<?> player, Permission Permission, int range) {
|
|
|
|
return hasPermissionRange(player, Permission.toString(), range);
|
2016-09-26 10:31:08 +02:00
|
|
|
}
|
|
|
|
|
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
|
2022-07-24 15:55:43 +02:00
|
|
|
* @deprecated all logic that may once have been in the class lives elsewhere. We also want to do away with statically-accessed
|
2023-01-15 14:08:59 +01:00
|
|
|
* 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);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|