mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Get rid of PermHandler
This commit is contained in:
@ -37,6 +37,7 @@ import com.plotsquared.core.events.PlayerAutoPlotEvent;
|
||||
import com.plotsquared.core.events.PlotAutoMergeEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.permissions.PermissionHandler;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
@ -175,9 +176,11 @@ public class Auto extends SubCommand {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
PlotArea plotarea = player.getApplicablePlotArea();
|
||||
if (plotarea == null) {
|
||||
if (this.econHandler != null) {
|
||||
for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||
if (this.econHandler.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
|
||||
final PermissionHandler permissionHandler = PlotSquared.platform().getPermissionHandler();
|
||||
if (permissionHandler.hasCapability(
|
||||
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
||||
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||
if (player.hasPermission(area.getWorldName(), "plots.auto")) {
|
||||
if (plotarea != null) {
|
||||
plotarea = null;
|
||||
break;
|
||||
|
@ -35,6 +35,7 @@ import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.permissions.PermissionHolder;
|
||||
import lombok.SneakyThrows;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -158,7 +159,7 @@ public abstract class Command {
|
||||
return this.allCommands;
|
||||
}
|
||||
|
||||
public boolean hasConfirmation(CommandCaller player) {
|
||||
public boolean hasConfirmation(PermissionHolder player) {
|
||||
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
|
||||
}
|
||||
|
||||
|
@ -34,14 +34,6 @@ public interface CommandCaller {
|
||||
*/
|
||||
void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* Check the player's permissions. <i>Will be cached if permission caching is enabled.</i>
|
||||
*
|
||||
* @param permission the name of the permission
|
||||
*/
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
boolean isPermissionSet(String permission);
|
||||
|
||||
RequiredType getSuperCaller();
|
||||
|
||||
}
|
||||
|
@ -26,11 +26,13 @@
|
||||
package com.plotsquared.core.permissions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public enum ConsolePermissionProfile implements PermissionProfile {
|
||||
INSTANCE;
|
||||
|
||||
@Override public boolean hasPermission(@Nonnull final String permission) {
|
||||
@Override public boolean hasPermission(@Nullable final String world,
|
||||
@Nonnull final String permission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,13 @@
|
||||
package com.plotsquared.core.permissions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public enum NullPermissionProfile implements PermissionProfile {
|
||||
INSTANCE;
|
||||
|
||||
@Override public boolean hasPermission(@Nonnull final String permission) {
|
||||
@Override public boolean hasPermission(@Nullable final String world,
|
||||
@Nonnull final String permission) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,11 @@ public interface PermissionHandler {
|
||||
/**
|
||||
* The ability to check for offline (player) permissions
|
||||
*/
|
||||
OFFLINE_PERMISSIONS
|
||||
OFFLINE_PERMISSIONS,
|
||||
/**
|
||||
* Per world permissions
|
||||
*/
|
||||
PER_WORLD_PERMISSIONS
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,12 @@
|
||||
*/
|
||||
package com.plotsquared.core.permissions;
|
||||
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Any object which can hold permissions
|
||||
@ -33,11 +38,57 @@ import javax.annotation.Nonnull;
|
||||
public interface PermissionHolder {
|
||||
|
||||
/**
|
||||
* Check if the permission holder has the given permission node
|
||||
* Check if the owner of the profile has a given (global) permission
|
||||
*
|
||||
* @param permission Permission node
|
||||
* @return {@code true} if the holder has the given permission node, else {@code false}
|
||||
* @param permission Permission
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
boolean hasPermission(@Nonnull String permission);
|
||||
default boolean hasPermission(@Nonnull final String permission) {
|
||||
return hasPermission(null ,permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*/
|
||||
@Nonnegative default int hasPermissionRange(@Nonnull final String stub,
|
||||
@Nonnegative final int range) {
|
||||
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
String[] nodes = stub.split("\\.");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
builder.append(nodes[i]).append(".");
|
||||
if (!stub.equals(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||
if (hasPermission(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasPermission(stub + ".*")) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given permission
|
||||
*
|
||||
* @param world World name
|
||||
* @param permission Permission
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
boolean hasPermission(@Nullable final String world, @Nonnull String permission);
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.permissions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A permission profile that can be used to check for permissions
|
||||
@ -33,11 +34,22 @@ import javax.annotation.Nonnull;
|
||||
public interface PermissionProfile {
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given permission
|
||||
* 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}
|
||||
*/
|
||||
boolean hasPermission(@Nonnull String permission);
|
||||
default boolean hasPermission(@Nonnull final String permission) {
|
||||
return hasPermission(null ,permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given permission
|
||||
*
|
||||
* @param world World name
|
||||
* @param permission Permission
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
boolean hasPermission(@Nullable final String world, @Nonnull String permission);
|
||||
|
||||
}
|
||||
|
@ -123,10 +123,6 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public boolean isPermissionSet(String permission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void sendMessage(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
@ -154,8 +154,9 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
||||
return PlotSquared.platform().wrapPlayer(player);
|
||||
}
|
||||
|
||||
@Override public final boolean hasPermission(@Nonnull final String permission) {
|
||||
return this.permissionProfile.hasPermission(permission);
|
||||
@Override public final boolean hasPermission(@Nullable final String world,
|
||||
@Nonnull final String permission) {
|
||||
return this.permissionProfile.hasPermission(world, permission);
|
||||
}
|
||||
|
||||
public abstract Actor toActor();
|
||||
@ -257,31 +258,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
||||
return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS);
|
||||
}
|
||||
|
||||
public int hasPermissionRange(String stub, int range) {
|
||||
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
String[] nodes = stub.split("\\.");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
builder.append(nodes[i]).append(".");
|
||||
if (!stub.equals(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||
if (hasPermission(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasPermission(stub + ".*")) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of plots this player owns.
|
||||
*
|
||||
|
@ -48,16 +48,4 @@ public abstract class EconHandler {
|
||||
|
||||
public abstract void depositMoney(OfflinePlotPlayer player, double amount);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
|
||||
*/
|
||||
@Deprecated public abstract boolean hasPermission(String world, String player, String perm);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link PermHandler#hasPermission(String, String)} instead
|
||||
*/
|
||||
@Deprecated public boolean hasPermission(String player, String perm) {
|
||||
return hasPermission(null, player, perm);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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;
|
||||
|
||||
public abstract class PermHandler {
|
||||
|
||||
public abstract boolean init();
|
||||
|
||||
public abstract boolean hasPermission(String world, String player, String perm);
|
||||
|
||||
public boolean hasPermission(String player, String perm) {
|
||||
return hasPermission(null, player, perm);
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import com.plotsquared.core.command.CommandCaller;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.permissions.PermissionHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -39,7 +40,7 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class Permissions {
|
||||
|
||||
public static boolean hasPermission(PlotPlayer player, Captions caption, boolean notify) {
|
||||
public static boolean hasPermission(PlotPlayer<?> player, Captions caption, boolean notify) {
|
||||
return hasPermission(player, caption.getTranslated(), notify);
|
||||
}
|
||||
|
||||
@ -50,7 +51,7 @@ public class Permissions {
|
||||
* @param caption
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasPermission(PlotPlayer player, Captions caption) {
|
||||
public static boolean hasPermission(PlotPlayer<?> player, Captions caption) {
|
||||
return hasPermission(player, caption.getTranslated());
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ public class Permissions {
|
||||
*/
|
||||
public static boolean hasPermission(PlotPlayer<?> player, String permission) {
|
||||
if (!Settings.Enabled_Components.PERMISSION_CACHE) {
|
||||
return hasPermission((CommandCaller) player, permission);
|
||||
return hasPermission((PermissionHolder) player, permission);
|
||||
}
|
||||
HashMap<String, Boolean> map = player.getMeta("perm");
|
||||
if (map != null) {
|
||||
@ -75,7 +76,7 @@ public class Permissions {
|
||||
map = new HashMap<>();
|
||||
player.setMeta("perm", map);
|
||||
}
|
||||
boolean result = hasPermission((CommandCaller) player, permission);
|
||||
boolean result = hasPermission((PermissionHolder) player, permission);
|
||||
map.put(permission, result);
|
||||
return result;
|
||||
}
|
||||
@ -87,12 +88,12 @@ public class Permissions {
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasPermission(CommandCaller caller, String permission) {
|
||||
public static boolean hasPermission(PermissionHolder caller, String permission) {
|
||||
if (caller.hasPermission(permission)) {
|
||||
return true;
|
||||
} else if (caller.isPermissionSet(permission)) {
|
||||
}/* TODO: DECIDE WHAT TO DO HERE; else if (caller.isPermissionSet(permission)) {
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
if (caller.hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||
return true;
|
||||
}
|
||||
@ -105,9 +106,9 @@ public class Permissions {
|
||||
if (!permission.equals(combined)) {
|
||||
if (caller.hasPermission(combined)) {
|
||||
return true;
|
||||
} else if (caller.isPermissionSet(combined)) {
|
||||
}/* TODO: DECIDE WHAT TO DO HERE; else if (caller.isPermissionSet(combined)) {
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -121,7 +122,7 @@ public class Permissions {
|
||||
* @param notify
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasPermission(PlotPlayer player, String permission, boolean notify) {
|
||||
public static boolean hasPermission(PlotPlayer<?> player, String permission, boolean notify) {
|
||||
if (!hasPermission(player, permission)) {
|
||||
if (notify) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, permission);
|
||||
@ -131,7 +132,7 @@ public class Permissions {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int hasPermissionRange(PlotPlayer player, Captions perm, int range) {
|
||||
public static int hasPermissionRange(PlotPlayer<?> player, Captions perm, int range) {
|
||||
return hasPermissionRange(player, perm.getTranslated(), range);
|
||||
}
|
||||
|
||||
@ -140,12 +141,12 @@ public class Permissions {
|
||||
* - Excessively high values will lag<br>
|
||||
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
|
||||
*
|
||||
* @param player
|
||||
* @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) {
|
||||
public static int hasPermissionRange(PlotPlayer<?> player, String stub, int range) {
|
||||
return player.hasPermissionRange(stub, range);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user