Get rid of PermHandler

This commit is contained in:
Alexander Söderberg 2020-07-22 12:35:48 +02:00
parent 532f2caa37
commit 9d6744ec15
22 changed files with 152 additions and 240 deletions

View File

@ -103,7 +103,6 @@ import com.plotsquared.core.util.ConsoleColors;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.FileUtils;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.ReflectionUtils;
@ -181,7 +180,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
private boolean methodUnloadSetup = false;
private boolean metricsStarted;
private EconHandler econ;
private PermHandler perm;
@Getter private Injector injector;
@ -340,10 +338,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
// Economy
if (Settings.Enabled_Components.ECONOMY) {
TaskManager.runTask(() -> {
final PermHandler permHandler = getInjector().getInstance(PermHandler.class);
if (permHandler != null) {
permHandler.init();
}
this.getPermissionHandler().initialize();
final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
if (econHandler != null) {
econHandler.init();

View File

@ -29,7 +29,6 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.util.Providers;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
@ -37,12 +36,9 @@ import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitPermHandler;
import com.plotsquared.bukkit.util.BukkitRegionManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.generator.HybridGen;
@ -58,7 +54,6 @@ import com.plotsquared.core.queue.QueueProvider;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
@ -70,7 +65,9 @@ import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@RequiredArgsConstructor public class BukkitModule extends AbstractModule {
@ -93,7 +90,6 @@ import javax.annotation.Nonnull;
bind(ChunkManager.class).to(BukkitChunkManager.class);
bind(RegionManager.class).to(BukkitRegionManager.class);
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
this.setupVault();
if (Settings.Enabled_Components.WORLDS) {
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
} else {
@ -102,25 +98,14 @@ import javax.annotation.Nonnull;
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
}
private void setupVault() {
@Provides @Singleton @Nullable EconHandler provideEconHandler() {
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
BukkitPermHandler bukkitPermHandler = null;
try {
bukkitPermHandler = new BukkitPermHandler();
bind(PermHandler.class).toInstance(bukkitPermHandler);
return new BukkitEconHandler();
} catch (final Exception ignored) {
bind(PermHandler.class).toProvider(Providers.of(null));
}
try {
final BukkitEconHandler bukkitEconHandler = new BukkitEconHandler(bukkitPermHandler);
bind(EconHandler.class).toInstance(bukkitEconHandler);
} catch (final Exception ignored) {
bind(EconHandler.class).toProvider(Providers.of(null));
}
} else {
bind(PermHandler.class).toProvider(Providers.of(null));
bind(EconHandler.class).toProvider(Providers.of(null));
}
return null;
}
}

View File

@ -31,17 +31,13 @@ import com.google.inject.Singleton;
import com.plotsquared.bukkit.permissions.BukkitPermissionHandler;
import com.plotsquared.bukkit.permissions.VaultPermissionHandler;
import com.plotsquared.core.permissions.PermissionHandler;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
public class PermissionModule extends AbstractModule {
@Provides @Singleton PermissionHandler providePermissionHandler() {
try {
RegisteredServiceProvider<Permission> permissionProvider =
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (permissionProvider != null) {
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
return new VaultPermissionHandler();
}
} catch (final Exception ignored) {

View File

@ -35,6 +35,7 @@ import com.plotsquared.core.player.PlotPlayer;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.EnumSet;
import java.util.Optional;
@ -74,7 +75,8 @@ public class BukkitPermissionHandler implements PermissionHandler {
this.playerReference = new WeakReference<>(player);
}
@Override public boolean hasPermission(@Nonnull final String permission) {
@Override public boolean hasPermission(@Nullable final String world,
@Nonnull final String permission) {
final Player player = this.playerReference.get();
return player != null && player.hasPermission(permission);
}

View File

@ -26,19 +26,25 @@
package com.plotsquared.bukkit.permissions;
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.core.permissions.ConsolePermissionProfile;
import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.permissions.PermissionProfile;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
public class VaultPermissionHandler extends BukkitPermissionHandler {
public class VaultPermissionHandler implements PermissionHandler {
private Permission permissions;
@ -53,6 +59,17 @@ public class VaultPermissionHandler extends BukkitPermissionHandler {
}
}
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
@Nonnull PlotPlayer<?> playerPlotPlayer) {
if (playerPlotPlayer instanceof BukkitPlayer) {
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
return Optional.of(new VaultPermissionProfile(bukkitPlayer.getPlatformPlayer()));
} else if (playerPlotPlayer instanceof ConsolePlayer) {
return Optional.of(ConsolePermissionProfile.INSTANCE);
}
return Optional.empty();
}
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
@Nonnull OfflinePlotPlayer offlinePlotPlayer) {
if (offlinePlotPlayer instanceof BukkitOfflinePlayer) {
@ -62,7 +79,9 @@ public class VaultPermissionHandler extends BukkitPermissionHandler {
}
@Nonnull @Override public Set<PermissionHandlerCapability> getCapabilities() {
return EnumSet.of(PermissionHandlerCapability.ONLINE_PERMISSIONS, PermissionHandlerCapability.OFFLINE_PERMISSIONS);
return EnumSet.of(PermissionHandlerCapability.PER_WORLD_PERMISSIONS,
PermissionHandlerCapability.ONLINE_PERMISSIONS,
PermissionHandlerCapability.OFFLINE_PERMISSIONS);
}
@ -74,11 +93,15 @@ public class VaultPermissionHandler extends BukkitPermissionHandler {
this.offlinePlayer = offlinePlayer;
}
@Override public boolean hasPermission(@Nonnull final String permission) {
@Override public boolean hasPermission(@Nullable final String world,
@Nonnull final String permission) {
if (permissions == null) {
return false;
}
return permissions.playerHas(null, offlinePlayer, permission);
if (world == null && offlinePlayer instanceof BukkitPlayer) {
return permissions.playerHas(((BukkitPlayer) offlinePlayer).getPlatformPlayer(), permission);
}
return permissions.playerHas(world, offlinePlayer, permission);
}
}

View File

@ -31,6 +31,7 @@ import com.plotsquared.core.permissions.PermissionProfile;
import com.plotsquared.core.player.OfflinePlotPlayer;
import org.bukkit.OfflinePlayer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID;
@ -68,8 +69,9 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
return this.player.getName();
}
@Override public boolean hasPermission(@Nonnull final String permission) {
return this.permissionProfile.hasPermission(permission);
@Override public boolean hasPermission(@Nullable final String world,
@Nonnull final String permission) {
return this.permissionProfile.hasPermission(world, permission);
}
}

View File

@ -54,6 +54,8 @@ import org.bukkit.event.EventException;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.RegisteredListener;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -164,7 +166,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
}
}
@Override public int hasPermissionRange(final String stub, final int range) {
@Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub,
@Nonnegative final int range) {
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
return Integer.MAX_VALUE;
}
@ -224,10 +227,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
return max;
}
@Override public boolean isPermissionSet(final String permission) {
return this.player.isPermissionSet(permission);
}
@Override public void sendMessage(String message) {
message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (

View File

@ -25,31 +25,21 @@
*/
package com.plotsquared.bukkit.util;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.PermHandler;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import javax.annotation.Nullable;
@Singleton public class BukkitEconHandler extends EconHandler {
private Economy econ;
private final PermHandler permHandler;
@Inject public BukkitEconHandler(@Nullable final PermHandler permHandler) {
this.permHandler = permHandler;
}
@Override
public boolean init() {
@Override public boolean init() {
if (this.econ == null) {
setupEconomy();
}
@ -87,17 +77,6 @@ import javax.annotation.Nullable;
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
}
/**
* @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
*/
@Deprecated @Override public boolean hasPermission(String world, String player, String perm) {
if (this.permHandler != null) {
return this.permHandler.hasPermission(world, player, perm);
} else {
return false;
}
}
@Override public double getBalance(PlotPlayer<?> player) {
return this.econ.getBalance(player.getName());
}

View File

@ -1,60 +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.bukkit.util;
import com.google.inject.Singleton;
import com.plotsquared.core.util.PermHandler;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
@Singleton public class BukkitPermHandler extends PermHandler {
private Permission perms;
@Override
public boolean init() {
if (this.perms == null) {
setupPermissions();
}
return this.perms != null;
}
private void setupPermissions() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return;
}
RegisteredServiceProvider<Permission> permissionProvider =
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (permissionProvider != null) {
this.perms = permissionProvider.getProvider();
}
}
@Override public boolean hasPermission(String world, String player, String perm) {
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
}
}

View File

@ -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;

View File

@ -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");
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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.
*

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}