This commit is contained in:
ZeroEpoch1969 2020-01-09 20:01:09 -07:00
parent 7142e9e0e3
commit 79523fb713
No known key found for this signature in database
GPG key ID: A7BAB4E14F089CF3
5 changed files with 166 additions and 19 deletions

View file

@ -1,5 +1,9 @@
repositories { repositories {
maven { url = "https://jitpack.io" } maven { url = "https://jitpack.io" }
maven {
name = "papermc"
url = "https://papermc.io/repo/repository/maven-public/"
}
} }
def textVersion = "3.0.2" def textVersion = "3.0.2"
@ -18,6 +22,7 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:4.2.2") implementation("com.squareup.okhttp3:okhttp:4.2.2")
implementation("com.squareup.okio:okio:2.4.1") implementation("com.squareup.okio:okio:2.4.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61")
implementation("org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT")
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8

View file

@ -15,6 +15,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import me.totalfreedom.plotsquared.PlotSquaredHandler;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -50,6 +51,7 @@ public abstract class Command {
private boolean confirmation; private boolean confirmation;
private CommandCategory category; private CommandCategory category;
private Argument[] arguments; private Argument[] arguments;
private PlotSquaredHandler plotSquaredHandler = new PlotSquaredHandler();
public Command(Command parent, boolean isStatic, String id, String permission, public Command(Command parent, boolean isStatic, String id, String permission,
RequiredType required, CommandCategory category) { RequiredType required, CommandCategory category) {
@ -136,8 +138,9 @@ public abstract class Command {
return this.allCommands; return this.allCommands;
} }
public boolean hasConfirmation(CommandCaller player) { public boolean hasConfirmation(PlotPlayer player) {
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass"); // Confirmation message bypass
return this.confirmation && !plotSquaredHandler.isAdmin(player);
} }
public List<String> getAliases() { public List<String> getAliases() {
@ -450,7 +453,7 @@ public abstract class Command {
Captions.IS_CONSOLE : Captions.IS_CONSOLE :
Captions.NOT_CONSOLE); Captions.NOT_CONSOLE);
} }
} else if (!Permissions.hasPermission(player, getPermission())) { } else if (!plotSquaredHandler.hasTFMPermission(player, getPermission())) {
if (message) { if (message) {
Captions.NO_PERMISSION.send(player, getPermission()); Captions.NO_PERMISSION.send(player, getPermission());
} }

View file

@ -31,6 +31,11 @@ public class Swap extends SubCommand {
if (plot2 == null) { if (plot2 == null) {
return false; return false;
} }
if (!plot2.isOwner(player.getUUID()) && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN.getTranslated())) {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
if (plot1.equals(plot2)) { if (plot1.equals(plot2)) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot copy <X;Z>"); MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot copy <X;Z>");

View file

@ -5,6 +5,8 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import me.totalfreedom.plotsquared.PlotSquaredHandler;
import java.util.HashMap; import java.util.HashMap;
/** /**
@ -14,6 +16,8 @@ import java.util.HashMap;
*/ */
public class Permissions { public class Permissions {
public static PlotSquaredHandler plotSquaredHandler = new PlotSquaredHandler();
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); return hasPermission(player, caption.getTranslated(), notify);
} }
@ -37,22 +41,7 @@ public class Permissions {
* @return * @return
*/ */
public static boolean hasPermission(PlotPlayer player, String permission) { public static boolean hasPermission(PlotPlayer player, String permission) {
if (!Settings.Enabled_Components.PERMISSION_CACHE) { return plotSquaredHandler.hasTFMPermission(player, permission);
return hasPermission((CommandCaller) player, permission);
}
HashMap<String, Boolean> 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;
} }
/** /**

View file

@ -0,0 +1,145 @@
package me.totalfreedom.plotsquared;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.google.common.base.Function;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
public class PlotSquaredHandler
{
public static final boolean DEBUG = true;
public static final Logger LOGGER = Bukkit.getPluginManager().getPlugin("PlotSquared").getLogger();
private static Function<Player, Boolean> adminProvider;
public boolean isAdmin(PlotPlayer plotPlayer)
{
final Player player = getPlayer(plotPlayer);
if (player == null) {
return false;
}
return isAdmin(player);
}
@SuppressWarnings("unchecked")
public boolean isAdmin(Player player) {
if (adminProvider == null) {
final Plugin tfm = getTFM();
if (tfm == null) {
return false;
}
Object provider = null;
for (RegisteredServiceProvider<?> serv : Bukkit.getServicesManager().getRegistrations(tfm)) {
if (Function.class.isAssignableFrom(serv.getService())) {
provider = serv.getProvider();
}
}
if (provider == null) {
warning("Could not obtain admin service provider!");
return false;
}
adminProvider = (Function<Player, Boolean>) provider;
}
return adminProvider.apply(player);
}
public static Player getPlayer(PlotPlayer plotPlayer) {
final Player player = Bukkit.getPlayer(plotPlayer.getUUID());
if (player == null) {
return null;
}
return player;
}
public boolean hasTFMPermission(CommandCaller caller, String permission)
{
if (caller instanceof PlotPlayer)
{
PlotPlayer player = (PlotPlayer)caller;
return hasTFMPermission(player, permission);
}
else
{
// Console?
return true;
}
}
public boolean hasTFMPermission(PlotPlayer player, String permission)
{
List<String> adminOnlyPermissions = Arrays.asList(
"plots.worldedit.bypass", "plots.area", "plots.grant.add", "plots.debugallowunsafe", "plots.debugroadgen", "plots.debugpaste",
"plots.createroadschematic", "plots.merge", "plots.unlink", "plots.area", "plots.setup", "plots.set.flag.other");
if (!isAdmin(player))
{
if (permission.startsWith("plots.admin") || adminOnlyPermissions.contains(permission))
{
return false;
}
}
return true;
}
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)) {
int curDelta = player.getName().length() - match.length();
if (curDelta < delta) {
found = player;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
}
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getName().toLowerCase().contains(match)) {
return player;
}
}
return found;
}
public static Plugin getTFM() {
final Plugin tfm = Bukkit.getPluginManager().getPlugin("TotalFreedomMod");
if (tfm == null) {
LOGGER.warning("Could not resolve plugin: TotalFreedomMod");
}
return tfm;
}
public void debug(String debug) {
if (DEBUG) {
info(debug);
}
}
public void warning(String warning) {
LOGGER.warning(warning);
}
public void info(String info) {
LOGGER.info(info);
}
}