From 9866ee5d80c1c1838cf37c54db34b6f29ec4c5b4 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Fri, 14 Aug 2020 13:50:28 -0500 Subject: [PATCH] Fat update --- Core/build.gradle | 8 ++ .../com/plotsquared/core/command/Command.java | 7 +- .../com/plotsquared/core/command/Swap.java | 5 ++ .../plotsquared/core/util/Permissions.java | 19 +---- .../plotsquared/PlotSquaredHandler.java | 74 ++++++++++--------- build.gradle | 8 ++ 6 files changed, 68 insertions(+), 53 deletions(-) diff --git a/Core/build.gradle b/Core/build.gradle index 51f56e187..68ef5e2be 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -1,6 +1,12 @@ repositories { maven { url = "https://jitpack.io" } maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" } + maven { + name = "spigot" + url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" + } + maven { url 'https://rayzr.dev/repo/' } + maven { url "https://repo.dmulloy2.net/nexus/repository/public/" } } def textVersion = "3.0.2" @@ -18,6 +24,8 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains:annotations:19.0.0") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") + implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") + implementation("com.github.TFPatches:TotalFreedomMod:server-SNAPSHOT") } sourceCompatibility = 1.8 diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java index 194fc48a4..40f8d8ee8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Command.java +++ b/Core/src/main/java/com/plotsquared/core/command/Command.java @@ -36,6 +36,7 @@ import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import lombok.SneakyThrows; +import me.totalfreedom.plotsquared.PlotSquaredHandler; import org.jetbrains.annotations.NotNull; import java.lang.reflect.InvocationTargetException; @@ -57,6 +58,7 @@ public abstract class Command { private final ArrayList allCommands = new ArrayList<>(); private final ArrayList dynamicCommands = new ArrayList<>(); private final HashMap staticCommands = new HashMap<>(); + private PlotSquaredHandler plotSquaredHandler = new PlotSquaredHandler(); // Parent command (may be null) private final Command parent; @@ -159,7 +161,8 @@ public abstract class Command { } public boolean hasConfirmation(CommandCaller player) { - return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass"); + // Confirmation message bypass + return this.confirmation && !plotSquaredHandler.isAdmin(player); } public List getAliases() { @@ -451,7 +454,7 @@ public abstract class Command { Captions.IS_CONSOLE : Captions.NOT_CONSOLE); } - } else if (!Permissions.hasPermission(player, getPermission())) { + } else if (!plotSquaredHandler.hasTFMPermission(player, getPermission())) { if (message) { Captions.NO_PERMISSION.send(player, getPermission()); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Swap.java b/Core/src/main/java/com/plotsquared/core/command/Swap.java index 9e7ce5208..00195a456 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Swap.java +++ b/Core/src/main/java/com/plotsquared/core/command/Swap.java @@ -67,6 +67,11 @@ public class Swap extends SubCommand { if (plot2 == null) { return CompletableFuture.completedFuture(false); } + if (!plot2.isOwner(player.getUUID()) && !Permissions + .hasPermission(player, Captions.PERMISSION_ADMIN.getTranslated())) { + MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); + return CompletableFuture.completedFuture(false); + } if (plot1.equals(plot2)) { MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot copy "); diff --git a/Core/src/main/java/com/plotsquared/core/util/Permissions.java b/Core/src/main/java/com/plotsquared/core/util/Permissions.java index 34754e7c8..8b808a27c 100644 --- a/Core/src/main/java/com/plotsquared/core/util/Permissions.java +++ b/Core/src/main/java/com/plotsquared/core/util/Permissions.java @@ -31,6 +31,7 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import java.util.HashMap; +import me.totalfreedom.plotsquared.PlotSquaredHandler; /** * The Permissions class handles checking user permissions.
@@ -38,6 +39,7 @@ import java.util.HashMap; * - Checking the PlotPlayer class directly will not take the above into account
*/ public class Permissions { + public static PlotSquaredHandler plotSquaredHandler = new PlotSquaredHandler(); public static boolean hasPermission(PlotPlayer player, Captions caption, boolean notify) { return hasPermission(player, caption.getTranslated(), notify); @@ -62,22 +64,7 @@ public class Permissions { * @return */ public static boolean hasPermission(PlotPlayer player, String permission) { - if (!Settings.Enabled_Components.PERMISSION_CACHE) { - return hasPermission((CommandCaller) player, permission); - } - HashMap map = player.getMeta("perm"); - if (map != null) { - Boolean result = map.get(permission); - if (result != null) { - return result; - } - } else { - map = new HashMap<>(); - player.setMeta("perm", map); - } - boolean result = hasPermission((CommandCaller) player, permission); - map.put(permission, result); - return result; + return plotSquaredHandler.hasTFMPermission(player, permission); } /** diff --git a/Core/src/main/java/me/totalfreedom/plotsquared/PlotSquaredHandler.java b/Core/src/main/java/me/totalfreedom/plotsquared/PlotSquaredHandler.java index 11b0e65d3..e4bbd2022 100644 --- a/Core/src/main/java/me/totalfreedom/plotsquared/PlotSquaredHandler.java +++ b/Core/src/main/java/me/totalfreedom/plotsquared/PlotSquaredHandler.java @@ -1,47 +1,42 @@ package me.totalfreedom.plotsquared; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.google.common.base.Function; - +import com.plotsquared.core.command.CommandCaller; +import com.plotsquared.core.player.PlotPlayer; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; public class PlotSquaredHandler { - public static final boolean DEBUG = true; public static final Logger LOGGER = Bukkit.getPluginManager().getPlugin("PlotSquared").getLogger(); private static Function adminProvider; - public boolean isAdmin(PlotPlayer plotPlayer) + public boolean isAdmin(CommandCaller commandCaller) { - final Player player = getPlayer(plotPlayer); - if (player == null) { + final Player player = getPlayer(commandCaller.toString()); + if (player == null) + { return false; } return isAdmin(player); } @SuppressWarnings("unchecked") - public boolean isAdmin(Player player) { + public boolean isAdmin(Player player) + { TotalFreedomMod tfm = getTFM(); return tfm.al.isAdmin(player); } - public static Player getPlayer(PlotPlayer plotPlayer) { - final Player player = Bukkit.getPlayer(plotPlayer.getUUID()); - - if (player == null) { - return null; - } - - return player; + public static Player getPlayer(CommandCaller commandCaller) + { + return Bukkit.getPlayer(commandCaller.toString()); } public boolean hasTFMPermission(CommandCaller caller, String permission) @@ -66,61 +61,70 @@ public class PlotSquaredHandler "plots.backup", "plots.debug"); if (!isAdmin(player)) { - if (permission.startsWith("plots.admin") || adminOnlyPermissions.contains(permission)) - { - return false; - } + return !permission.startsWith("plots.admin") && !adminOnlyPermissions.contains(permission); } return true; } - public static Player getPlayer(String match) { + public static Player getPlayer(String match) + { match = match.toLowerCase(); Player found = null; int delta = Integer.MAX_VALUE; - for (Player player : Bukkit.getOnlinePlayers()) { - if (player.getName().toLowerCase().startsWith(match)) { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.getName().toLowerCase().startsWith(match)) + { int curDelta = player.getName().length() - match.length(); - if (curDelta < delta) { + if (curDelta < delta) + { found = player; delta = curDelta; } - if (curDelta == 0) { + if (curDelta == 0) + { break; } } } - for (Player player : Bukkit.getOnlinePlayers()) { - if (player.getName().toLowerCase().contains(match)) { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.getName().toLowerCase().contains(match)) + { return player; } } return found; } - public static TotalFreedomMod getTFM() { + public static TotalFreedomMod getTFM() + { final Plugin tfm = Bukkit.getPluginManager().getPlugin("TotalFreedomMod"); - if (tfm == null) { + if (tfm == null) + { LOGGER.warning("Could not resolve plugin: TotalFreedomMod"); } return (TotalFreedomMod)tfm; } - public void debug(String debug) { - if (DEBUG) { + public void debug(String debug) + { + if (DEBUG) + { info(debug); } } - public void warning(String warning) { + public void warning(String warning) + { LOGGER.warning(warning); } - public void info(String info) { + public void info(String info) + { LOGGER.info(info); } - } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 9db7e5b6f..996e675f5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,12 @@ buildscript { mavenCentral() maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() + maven { + name = "spigot" + url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" + } + maven { url 'https://rayzr.dev/repo/' } + maven { url "https://repo.dmulloy2.net/nexus/repository/public/" } } dependencies { classpath("com.github.jengelman.gradle.plugins:shadow:5.0.0") @@ -100,6 +106,8 @@ subprojects { annotationProcessor("org.projectlombok:lombok:1.18.8") testAnnotationProcessor("org.projectlombok:lombok:1.18.8") testImplementation("junit:junit:4.13") + implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") + implementation("com.github.TFPatches:TotalFreedomMod:server-SNAPSHOT") } configurations.all {