mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-06-28 10:45:02 +02:00
# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java # Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java # Core/pom.xml # Core/src/main/java/com/plotsquared/core/PlotAPI.java # Core/src/main/java/com/plotsquared/core/PlotPlatform.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Auto.java # Core/src/main/java/com/plotsquared/core/command/Claim.java # Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java # Core/src/main/java/com/plotsquared/core/command/Command.java # Core/src/main/java/com/plotsquared/core/command/CommandCaller.java # Core/src/main/java/com/plotsquared/core/command/DebugExec.java # Core/src/main/java/com/plotsquared/core/command/Grant.java # Core/src/main/java/com/plotsquared/core/command/Inbox.java # Core/src/main/java/com/plotsquared/core/command/Load.java # Core/src/main/java/com/plotsquared/core/command/Save.java # Core/src/main/java/com/plotsquared/core/command/Setup.java # Core/src/main/java/com/plotsquared/core/listener/PlotListener.java # Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java # Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java # Core/src/main/java/com/plotsquared/core/util/BlockUtil.java # Core/src/main/java/com/plotsquared/core/util/Permissions.java
108 lines
4.4 KiB
Java
108 lines
4.4 KiB
Java
/*
|
|
* _____ _ _ _____ _
|
|
* | __ \| | | | / ____| | |
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
* | |
|
|
* |_|
|
|
* PlotSquared plot management system for Minecraft
|
|
* Copyright (C) 2020 IntellectualSites
|
|
*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.plotsquared.core.util;
|
|
|
|
import com.plotsquared.core.configuration.Caption;
|
|
import com.plotsquared.core.configuration.Captions;
|
|
import com.plotsquared.core.configuration.Settings;
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
|
import com.plotsquared.core.permissions.PermissionHolder;
|
|
import com.plotsquared.core.player.PlotPlayer;
|
|
import net.kyori.adventure.text.minimessage.Template;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
/**
|
|
* The Permissions class handles checking user permissions.<br>
|
|
* - 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>
|
|
*/
|
|
public class Permissions {
|
|
|
|
public static boolean hasPermission(PlotPlayer<?> player, Captions caption, boolean notify) {
|
|
return hasPermission(player, caption.getTranslated(), notify);
|
|
}
|
|
|
|
/**
|
|
* Check if the owner of the profile has a given (global) permission
|
|
*
|
|
* @param permission Permission
|
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
|
*/
|
|
public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final Caption permission) {
|
|
return caller.hasPermission(permission.getTranslated());
|
|
}
|
|
|
|
/**
|
|
* Check if the owner of the profile has a given (global) permission
|
|
*
|
|
* @param permission Permission
|
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
|
*/
|
|
public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final String permission) {
|
|
return caller.hasPermission(permission);
|
|
}
|
|
|
|
/**
|
|
* Checks if a PlotPlayer has a permission, and optionally send the no permission message if applicable.
|
|
*
|
|
* @param player
|
|
* @param permission
|
|
* @param notify
|
|
* @return
|
|
*/
|
|
public static boolean hasPermission(PlotPlayer<?> player, String permission, boolean notify) {
|
|
if (!hasPermission(player, permission)) {
|
|
if (notify) {
|
|
player.sendMessage(
|
|
TranslatableCaption.of("permission.no_permission_event"),
|
|
Template.of("node", permission)
|
|
);
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static int hasPermissionRange(PlotPlayer<?> player, Captions perm, int range) {
|
|
return hasPermissionRange(player, perm.getTranslated(), range);
|
|
}
|
|
|
|
/**
|
|
* Check the the highest permission a PlotPlayer has within a specified range.<br>
|
|
* - Excessively high values will lag<br>
|
|
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
|
|
*
|
|
* @param player Player to check for
|
|
* @param stub The permission stub to check e.g. for `plots.plot.#` the stub is `plots.plot`
|
|
* @param range The range to check
|
|
* @return The highest permission they have within that range
|
|
*/
|
|
public static int hasPermissionRange(PlotPlayer<?> player, String stub, int range) {
|
|
return player.hasPermissionRange(stub, range);
|
|
}
|
|
}
|