diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java index 6a19af208..fd51014c7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Auto.java +++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java @@ -28,8 +28,6 @@ package com.plotsquared.core.command; import com.google.common.collect.Lists; import com.google.inject.Inject; 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.caption.TranslatableCaption; 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.Result; 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.PlayerMetaDataKeys; -import com.plotsquared.core.permissions.PermissionHandler; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -284,9 +283,7 @@ public class Auto extends SubCommand { ); return true; } - if (!force && !Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_CLAIM_SCHEMATIC.toString(), schematic)) - && !Permissions + if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)) && !Permissions .hasPermission(player, "plots.admin.command.schematic")) { player.sendMessage( TranslatableCaption.of("permission.no_permission"), diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 5227e04c7..6b6282d87 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -126,10 +126,8 @@ public class Claim extends SubCommand { Template.of("reason", "non-existant") ); } - if (!Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_CLAIM_SCHEMATIC.toString(), - schematic)) && !Permissions.hasPermission(player, "plots.admin.command.schematic") - && !force) { + if (!Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC + .format(schematic)) && !Permissions.hasPermission(player, "plots.admin.command.schematic") && !force) { player.sendMessage( TranslatableCaption.of("permission.no_schematic_permission"), Template.of("value", schematic) diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java index c71317f12..cfd8bc634 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -26,9 +26,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.permissions.Permission; 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.Templates; 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.Result; import com.plotsquared.core.location.Location; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; 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) { key = key.toLowerCase(); value = value.toLowerCase(); - String perm = CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), - key.toLowerCase(), value.toLowerCase()); + String perm = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase()); if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { try { int numeric = Integer.parseInt(value); @@ -108,9 +105,8 @@ public final class FlagCommand extends Command { Settings.Limit.MAX_PLOTS; final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric; if (!result) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), - key.toLowerCase(), value.toLowerCase())); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase()))); } return result; } @@ -121,14 +117,10 @@ public final class FlagCommand extends Command { try { PlotFlag, ?> parsedFlag = listFlag.parse(value); for (final Object entry : parsedFlag.getValue()) { - final String permission = CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), - key.toLowerCase(), entry.toString().toLowerCase()); + final String permission = Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), entry.toString().toLowerCase()); final boolean result = Permissions.hasPermission(player, permission); if (!result) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), - key.toLowerCase(), value.toLowerCase())); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", permission)); return false; } } @@ -147,9 +139,7 @@ public final class FlagCommand extends Command { } final boolean result = Permissions.hasPermission(player, perm); if (!result) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY_VALUE.toString(), - key.toLowerCase(), value.toLowerCase())); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", perm)); } return result; } @@ -440,13 +430,10 @@ public final class FlagCommand extends Command { } boolean force = event.getEventResult() == Result.FORCE; flag = event.getFlag(); - if (!force && !Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY.toString(), - args[0].toLowerCase()))) { + if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase()))) { if (args.length != 2) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_SET_FLAG_KEY.toString(), - args[0].toLowerCase())); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_SET_FLAG_KEY.format(args[0].toLowerCase()))); return; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Grant.java b/Core/src/main/java/com/plotsquared/core/command/Grant.java index 2ad6ff933..33c3f042b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Grant.java +++ b/Core/src/main/java/com/plotsquared/core/command/Grant.java @@ -27,10 +27,9 @@ package com.plotsquared.core.command; import com.google.common.primitives.Ints; 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.database.DBFunc; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; @@ -66,10 +65,9 @@ public class Grant extends Command { switch (arg0) { case "add": case "check": - if (!Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_GRANT.toString(), arg0))) { - Permission.NO_PERMISSION.send(player, CaptionUtility - .format(player, Permission.PERMISSION_GRANT.toString(), arg0)); + if (!Permissions.hasPermission(player, Permission.PERMISSION_GRANT.format(arg0))) { + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_GRANT.format(arg0))); return CompletableFuture.completedFuture(false); } if (args.length > 2) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 423255f51..b63a8a8c1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -27,11 +27,10 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.backup.BackupManager; -import com.plotsquared.core.permissions.Permission; 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.TranslatableCaption; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -140,12 +139,9 @@ public class Set extends SubCommand { for (String component : components) { if (component.equalsIgnoreCase(args[0])) { - if (!Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_SET_COMPONENT.toString(), - component))) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_SET_COMPONENT.toString(), - component)); + if (!Permissions.hasPermission(player, Permission.PERMISSION_SET_COMPONENT.format(component))) { + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_SET_COMPONENT.format(component))); return false; } if (args.length < 2) { diff --git a/Core/src/main/java/com/plotsquared/core/command/SetCommand.java b/Core/src/main/java/com/plotsquared/core/command/SetCommand.java index ddb4b0fb0..a8e4a973c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SetCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/SetCommand.java @@ -25,14 +25,14 @@ */ 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.location.Location; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; +import net.kyori.adventure.text.minimessage.Template; public abstract class SetCommand extends SubCommand { @@ -44,21 +44,17 @@ public abstract class SetCommand extends SubCommand { return false; } if (!plot.hasOwner()) { - if (!Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), getFullId()))) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), - getFullId())); + if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) { + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))); player.sendMessage(TranslatableCaption.of("working.plot_not_claimed")); return false; } } if (!plot.isOwner(player.getUUID())) { - if (!Permissions.hasPermission(player, CaptionUtility - .format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), getFullId()))) { - MainUtil.sendMessage(player, Permission.NO_PERMISSION, CaptionUtility - .format(player, Permission.PERMISSION_ADMIN_COMMAND.toString(), - getFullId())); + if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) { + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))); player.sendMessage(TranslatableCaption.of("permission.no_plot_perms")); return false; } diff --git a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java index c2ac0f34d..ff1b913ef 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java @@ -75,7 +75,7 @@ public enum Permission { PERMISSION_AREA_REGEN("plots.area.regen"), PERMISSION_AREA_TP("plots.area.tp"), 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_CLEAR("plots.admin.command.clear"), PERMISSION_CONTINUE("plots.continue"), @@ -110,18 +110,18 @@ public enum Permission { PERMISSION_DOWNLOAD_WORLD("plots.download.world"), PERMISSION_SET_FLAG_OTHER("plots.set.flag.other"), PERMISSION_SET_FLAG("plots.set.flag"), - PERMISSION_SET_FLAG_KEY("plots.set.flag.%s0"), - PERMISSION_SET_FLAG_KEY_VALUE("plots.set.flag.%s0.%s1"), + PERMISSION_SET_FLAG_KEY("plots.set.flag.%s"), + PERMISSION_SET_FLAG_KEY_VALUE("plots.set.flag.%s.%s"), PERMISSION_FLAG_REMOVE("plots.flag.remove"), PERMISSION_FLAG_ADD("plots.flag.add"), PERMISSION_FLAG_LIST("plots.flag.list"), 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_MINE("plots.list.mine"), PERMISSION_LIST_SHARED("plots.list.shared"), 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_ALL("plots.list.all"), PERMISSION_LIST_UNOWNED("plots.list.unowned"), @@ -142,8 +142,8 @@ public enum Permission { PERMISSION_SCHEMATIC_LIST("plots.schematic.list"), PERMISSION_SCHEMATIC_SAVE("plots.schematic.save"), PERMISSION_ADMIN_COMMAND_SCHEMATIC_SAVE("plots.admin.command.schematic.save"), - PERMISSION_SET_COMPONENT("plots.set.%s0"), - PERMISSION_ADMIN_COMMAND("plots.admin.command.%s0"), + PERMISSION_SET_COMPONENT("plots.set.%s"), + PERMISSION_ADMIN_COMMAND("plots.admin.command.%s"), PERMISSION_ADMIN_COMMAND_UNLINK("plots.ad2min.command.unlink"), PERMISSION_VISIT_UNOWNED("plots.visit.unowned"), PERMISSION_VISIT_OWNED("plots.visit.owned"), @@ -176,4 +176,8 @@ public enum Permission { return this.text; } + public String format(Object... replacements) { + return String.format(this.toString(), replacements); + } + }