Implement Permission#format to replace the CaptionUtility#format method

This commit is contained in:
dordsor21 2020-08-07 12:12:16 +01:00
parent 21a97863ac
commit 6012705e95
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
7 changed files with 42 additions and 66 deletions

View File

@ -28,8 +28,6 @@ package com.plotsquared.core.command;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
@ -37,9 +35,10 @@ import com.plotsquared.core.events.PlayerAutoPlotEvent;
import com.plotsquared.core.events.PlotAutoMergeEvent; import com.plotsquared.core.events.PlotAutoMergeEvent;
import com.plotsquared.core.events.Result; import com.plotsquared.core.events.Result;
import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.MetaDataAccess;
import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
@ -284,9 +283,7 @@ public class Auto extends SubCommand {
); );
return true; return true;
} }
if (!force && !Permissions.hasPermission(player, CaptionUtility if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)) && !Permissions
.format(player, Permission.PERMISSION_CLAIM_SCHEMATIC.toString(), schematic))
&& !Permissions
.hasPermission(player, "plots.admin.command.schematic")) { .hasPermission(player, "plots.admin.command.schematic")) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),

View File

@ -126,10 +126,8 @@ public class Claim extends SubCommand {
Template.of("reason", "non-existant") Template.of("reason", "non-existant")
); );
} }
if (!Permissions.hasPermission(player, CaptionUtility if (!Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC
.format(player, Permission.PERMISSION_CLAIM_SCHEMATIC.toString(), .format(schematic)) && !Permissions.hasPermission(player, "plots.admin.command.schematic") && !force) {
schematic)) && !Permissions.hasPermission(player, "plots.admin.command.schematic")
&& !force) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_schematic_permission"), TranslatableCaption.of("permission.no_schematic_permission"),
Template.of("value", schematic) Template.of("value", schematic)

View File

@ -26,9 +26,7 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
@ -36,6 +34,7 @@ import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent;
import com.plotsquared.core.events.Result; import com.plotsquared.core.events.Result;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.FlagParseException; import com.plotsquared.core.plot.flag.FlagParseException;
@ -95,9 +94,7 @@ public final class FlagCommand extends Command {
@Nonnull final PlotFlag<?, ?> flag, @Nonnull String key, @Nonnull String value) { @Nonnull final PlotFlag<?, ?> flag, @Nonnull String key, @Nonnull String value) {
key = key.toLowerCase(); key = key.toLowerCase();
value = value.toLowerCase(); value = value.toLowerCase();
String perm = CaptionUtility String perm = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase());
.format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(),
key.toLowerCase(), value.toLowerCase());
if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { if (flag instanceof IntegerFlag && MathMan.isInteger(value)) {
try { try {
int numeric = Integer.parseInt(value); int numeric = Integer.parseInt(value);
@ -108,9 +105,8 @@ public final class FlagCommand extends Command {
Settings.Limit.MAX_PLOTS; Settings.Limit.MAX_PLOTS;
final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric; final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric;
if (!result) { if (!result) {
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility player.sendMessage(TranslatableCaption.of("permission.no_permission"),
.format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), Template.of("node", Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase())));
key.toLowerCase(), value.toLowerCase()));
} }
return result; return result;
} }
@ -121,14 +117,10 @@ public final class FlagCommand extends Command {
try { try {
PlotFlag<? extends List<?>, ?> parsedFlag = listFlag.parse(value); PlotFlag<? extends List<?>, ?> parsedFlag = listFlag.parse(value);
for (final Object entry : parsedFlag.getValue()) { for (final Object entry : parsedFlag.getValue()) {
final String permission = CaptionUtility final String permission = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), entry.toString().toLowerCase());
.format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(),
key.toLowerCase(), entry.toString().toLowerCase());
final boolean result = Permissions.hasPermission(player, permission); final boolean result = Permissions.hasPermission(player, permission);
if (!result) { if (!result) {
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", permission));
.format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(),
key.toLowerCase(), value.toLowerCase()));
return false; return false;
} }
} }
@ -147,9 +139,7 @@ public final class FlagCommand extends Command {
} }
final boolean result = Permissions.hasPermission(player, perm); final boolean result = Permissions.hasPermission(player, perm);
if (!result) { if (!result) {
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", perm));
.format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(),
key.toLowerCase(), value.toLowerCase()));
} }
return result; return result;
} }
@ -440,13 +430,10 @@ public final class FlagCommand extends Command {
} }
boolean force = event.getEventResult() == Result.FORCE; boolean force = event.getEventResult() == Result.FORCE;
flag = event.getFlag(); flag = event.getFlag();
if (!force && !Permissions.hasPermission(player, CaptionUtility if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase()))) {
.format(player, Permission.PERMISSION_SET_FLAG_KEY.toString(),
args[0].toLowerCase()))) {
if (args.length != 2) { if (args.length != 2) {
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility player.sendMessage(TranslatableCaption.of("permission.no_permission"),
.format(player, Permission.PERMISSION_SET_FLAG_KEY.toString(), Template.of("node", Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase())));
args[0].toLowerCase()));
return; return;
} }
} }

View File

@ -27,10 +27,9 @@ package com.plotsquared.core.command;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.MetaDataAccess;
import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -66,10 +65,9 @@ public class Grant extends Command {
switch (arg0) { switch (arg0) {
case "add": case "add":
case "check": case "check":
if (!Permissions.hasPermission(player, CaptionUtility if (!Permissions.hasPermission(player, Permission.PERMISSION_GRANT.format(arg0))) {
.format(player, Permission.PERMISSION_GRANT.toString(), arg0))) { player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Permission.NO_PERMISSION.send(player, CaptionUtility Template.of("node", Permission.PERMISSION_GRANT.format(arg0)));
.format(player, Permission.PERMISSION_GRANT.toString(), arg0));
return CompletableFuture.completedFuture(false); return CompletableFuture.completedFuture(false);
} }
if (args.length > 2) { if (args.length > 2) {

View File

@ -27,11 +27,10 @@ package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
@ -140,12 +139,9 @@ public class Set extends SubCommand {
for (String component : components) { for (String component : components) {
if (component.equalsIgnoreCase(args[0])) { if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(player, CaptionUtility if (!Permissions.hasPermission(player, Permission.PERMISSION_SET_COMPONENT.format(component))) {
.format(player, Permission.PERMISSION_SET_COMPONENT.toString(), player.sendMessage(TranslatableCaption.of("permission.no_permission"),
component))) { Template.of("node", Permission.PERMISSION_SET_COMPONENT.format(component)));
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility
.format(player, Permission.PERMISSION_SET_COMPONENT.toString(),
component));
return false; return false;
} }
if (args.length < 2) { if (args.length < 2) {

View File

@ -25,14 +25,14 @@
*/ */
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.StringMan;
import net.kyori.adventure.text.minimessage.Template;
public abstract class SetCommand extends SubCommand { public abstract class SetCommand extends SubCommand {
@ -44,21 +44,17 @@ public abstract class SetCommand extends SubCommand {
return false; return false;
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, CaptionUtility if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
.format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), getFullId()))) { player.sendMessage(TranslatableCaption.of("permission.no_permission"),
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())));
.format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(),
getFullId()));
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed")); player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
return false; return false;
} }
} }
if (!plot.isOwner(player.getUUID())) { if (!plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, CaptionUtility if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
.format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), getFullId()))) { player.sendMessage(TranslatableCaption.of("permission.no_permission"),
MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())));
.format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(),
getFullId()));
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms")); player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false; return false;
} }

View File

@ -75,7 +75,7 @@ public enum Permission {
PERMISSION_AREA_REGEN("plots.area.regen"), PERMISSION_AREA_REGEN("plots.area.regen"),
PERMISSION_AREA_TP("plots.area.tp"), PERMISSION_AREA_TP("plots.area.tp"),
PERMISSION_AUTO_MEGA("plots.auto.mega"), PERMISSION_AUTO_MEGA("plots.auto.mega"),
PERMISSION_CLAIM_SCHEMATIC("plots.claim.%s0"), PERMISSION_CLAIM_SCHEMATIC("plots.claim.%s"),
PERMISSION_ADMIN_COMMAND_SCHEMATIC("plots.admin.command.schematic"), PERMISSION_ADMIN_COMMAND_SCHEMATIC("plots.admin.command.schematic"),
PERMISSION_ADMIN_COMMAND_CLEAR("plots.admin.command.clear"), PERMISSION_ADMIN_COMMAND_CLEAR("plots.admin.command.clear"),
PERMISSION_CONTINUE("plots.continue"), PERMISSION_CONTINUE("plots.continue"),
@ -110,18 +110,18 @@ public enum Permission {
PERMISSION_DOWNLOAD_WORLD("plots.download.world"), PERMISSION_DOWNLOAD_WORLD("plots.download.world"),
PERMISSION_SET_FLAG_OTHER("plots.set.flag.other"), PERMISSION_SET_FLAG_OTHER("plots.set.flag.other"),
PERMISSION_SET_FLAG("plots.set.flag"), PERMISSION_SET_FLAG("plots.set.flag"),
PERMISSION_SET_FLAG_KEY("plots.set.flag.%s0"), PERMISSION_SET_FLAG_KEY("plots.set.flag.%s"),
PERMISSION_SET_FLAG_KEY_VALUE("plots.set.flag.%s0.%s1"), PERMISSION_SET_FLAG_KEY_VALUE("plots.set.flag.%s.%s"),
PERMISSION_FLAG_REMOVE("plots.flag.remove"), PERMISSION_FLAG_REMOVE("plots.flag.remove"),
PERMISSION_FLAG_ADD("plots.flag.add"), PERMISSION_FLAG_ADD("plots.flag.add"),
PERMISSION_FLAG_LIST("plots.flag.list"), PERMISSION_FLAG_LIST("plots.flag.list"),
PERMISSION_ADMIN_COMMAND_KICK("plots.admin.command.kick"), PERMISSION_ADMIN_COMMAND_KICK("plots.admin.command.kick"),
PERMISSION_GRANT("plots.grant.%s0"), PERMISSION_GRANT("plots.grant.%s"),
PERMISSION_LIST_FOR_SALE("plots.list.forsale"), PERMISSION_LIST_FOR_SALE("plots.list.forsale"),
PERMISSION_LIST_MINE("plots.list.mine"), PERMISSION_LIST_MINE("plots.list.mine"),
PERMISSION_LIST_SHARED("plots.list.shared"), PERMISSION_LIST_SHARED("plots.list.shared"),
PERMISSION_LIST_WORLD("plots.list.world"), PERMISSION_LIST_WORLD("plots.list.world"),
PERMISSION_LIST_WORLD_NAME("plots.list.world.%s0"), PERMISSION_LIST_WORLD_NAME("plots.list.world.%s"),
PERMISSION_LIST_TOP("plots.list.top"), PERMISSION_LIST_TOP("plots.list.top"),
PERMISSION_LIST_ALL("plots.list.all"), PERMISSION_LIST_ALL("plots.list.all"),
PERMISSION_LIST_UNOWNED("plots.list.unowned"), PERMISSION_LIST_UNOWNED("plots.list.unowned"),
@ -142,8 +142,8 @@ public enum Permission {
PERMISSION_SCHEMATIC_LIST("plots.schematic.list"), PERMISSION_SCHEMATIC_LIST("plots.schematic.list"),
PERMISSION_SCHEMATIC_SAVE("plots.schematic.save"), PERMISSION_SCHEMATIC_SAVE("plots.schematic.save"),
PERMISSION_ADMIN_COMMAND_SCHEMATIC_SAVE("plots.admin.command.schematic.save"), PERMISSION_ADMIN_COMMAND_SCHEMATIC_SAVE("plots.admin.command.schematic.save"),
PERMISSION_SET_COMPONENT("plots.set.%s0"), PERMISSION_SET_COMPONENT("plots.set.%s"),
PERMISSION_ADMIN_COMMAND("plots.admin.command.%s0"), PERMISSION_ADMIN_COMMAND("plots.admin.command.%s"),
PERMISSION_ADMIN_COMMAND_UNLINK("plots.ad2min.command.unlink"), PERMISSION_ADMIN_COMMAND_UNLINK("plots.ad2min.command.unlink"),
PERMISSION_VISIT_UNOWNED("plots.visit.unowned"), PERMISSION_VISIT_UNOWNED("plots.visit.unowned"),
PERMISSION_VISIT_OWNED("plots.visit.owned"), PERMISSION_VISIT_OWNED("plots.visit.owned"),
@ -176,4 +176,8 @@ public enum Permission {
return this.text; return this.text;
} }
public String format(Object... replacements) {
return String.format(this.toString(), replacements);
}
} }