diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index a0f19cb6e..b313098a8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -45,6 +45,7 @@ import com.plotsquared.bukkit.util.BukkitChatManager; 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.BukkitTaskManager; @@ -94,6 +95,7 @@ import com.plotsquared.core.util.ConsoleColors; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.PermHandler; import com.plotsquared.core.util.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.PremiumVerification; @@ -179,6 +181,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Getter private PlatformWorldManager worldManager; private final BukkitPlayerManager playerManager = new BukkitPlayerManager(); private EconHandler econ; + private PermHandler perm; @Override public int[] getServerVersion() { if (this.version == null) { @@ -904,7 +907,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Override public EconHandler getEconomyHandler() { if (econ != null) { - if (econ.init() /* is inited*/) { + if (econ.init() /* is inited */) { return econ; } else { return null; @@ -922,6 +925,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return null; } + @Override public PermHandler getPermissionHandler() { + if (perm != null) { + if (perm.init() /* is inited */) { + return perm; + } else { + return null; + } + } + + try { + perm = new BukkitPermHandler(); + if (perm.init()) { + return perm; + } + } catch (Throwable ignored) { + PlotSquared.debug("No permissions detected!"); + } + return null; + } + @Override public QueueProvider initBlockQueue() { //TODO Figure out why this code is still here yet isn't being called anywhere. // try { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 642ed3c63..e71c48158 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -27,34 +27,25 @@ package com.plotsquared.bukkit.util; import com.plotsquared.bukkit.player.BukkitOfflinePlayer; import com.plotsquared.bukkit.player.BukkitPlayer; +import com.plotsquared.core.PlotSquared; 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 net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; public class BukkitEconHandler extends EconHandler { private Economy econ; - private Permission perms; @Override public boolean init() { - if (this.econ == null || this.perms == null) { - setupPermissions(); + if (this.econ == null) { setupEconomy(); } - return this.econ != null && this.perms != null; - } - - private void setupPermissions() { - RegisteredServiceProvider permissionProvider = - Bukkit.getServer().getServicesManager().getRegistration(Permission.class); - if (permissionProvider != null) { - this.perms = permissionProvider.getProvider(); - } + return this.econ != null; } private void setupEconomy() { @@ -88,20 +79,19 @@ public class BukkitEconHandler extends EconHandler { this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount); } - @Override public boolean hasPermission(String world, String player, String perm) { - return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm); + /** + * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead + */ + @Deprecated @Override public boolean hasPermission(String world, String player, String perm) { + if (PlotSquared.imp().getPermissionHandler() != null) { + return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm); + } else { + return false; + } } @Override public double getBalance(PlotPlayer player) { return this.econ.getBalance(player.getName()); } - @Deprecated public void setPermission(String world, String player, String perm, boolean value) { - if (value) { - this.perms.playerAdd(world, player, perm); - } else { - this.perms.playerRemove(world, player, perm); - } - } - } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java new file mode 100644 index 000000000..fee00a66d --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java @@ -0,0 +1,59 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * 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 . + */ +package com.plotsquared.bukkit.util; + +import com.plotsquared.core.util.PermHandler; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.Bukkit; +import org.bukkit.plugin.RegisteredServiceProvider; + +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 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); + } +} diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java index 4dc293c6d..a38045acb 100644 --- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java +++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java @@ -35,6 +35,7 @@ import com.plotsquared.core.util.ChatManager; 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.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.RegionManager; @@ -180,6 +181,13 @@ public interface IPlotMain

extends ILogger { */ @Nullable EconHandler getEconomyHandler(); + /** + * Gets the permission provider, if there is one + * + * @return the PlotSquared permission manager + */ + @Nullable PermHandler getPermissionHandler(); + /** * Gets the {@link QueueProvider} class. */ diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index 1064b0800..a593e0cb0 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -77,9 +77,15 @@ public abstract class EconHandler { public abstract void depositMoney(OfflinePlotPlayer player, double amount); - public abstract boolean hasPermission(String world, String player, String perm); + /** + * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead + */ + @Deprecated public abstract boolean hasPermission(String world, String player, String perm); - public boolean hasPermission(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); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/PermHandler.java b/Core/src/main/java/com/plotsquared/core/util/PermHandler.java new file mode 100644 index 000000000..1dec45fd4 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/util/PermHandler.java @@ -0,0 +1,37 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * 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 . + */ +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); + } +}