Use hasPermissionRange to check for trust and add limits

This commit is contained in:
N0tMyFaultOG 2020-12-28 15:36:00 +01:00
parent fafdae9ba9
commit 0fcca4c141
No known key found for this signature in database
GPG Key ID: 823348042DA95A81
4 changed files with 16 additions and 5 deletions

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.permissions.Permission; 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;
@ -114,8 +115,11 @@ public class Add extends Command {
size += plot.getTrusted().contains(uuid) ? 0 : 1; size += plot.getTrusted().contains(uuid) ? 0 : 1;
} }
checkTrue(!uuids.isEmpty(), null); checkTrue(!uuids.isEmpty(), null);
if (!(player.hasPermission("plots.add." + size) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_ADD))) int maxAddSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS);
player.sendMessage(TranslatableCaption.of("members.plot_max_members"), Template.of("amount", String.valueOf(size - 1))); if (size > maxAddSize) {
player.sendMessage(TranslatableCaption.of("members.plot_max_members_added"), Template.of("amount", String.valueOf(size - 1)));
return;
}
// Success // Success
confirm.run(this, () -> { confirm.run(this, () -> {
for (UUID uuid : uuids) { for (UUID uuid : uuids) {

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.permissions.Permission;
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;
@ -128,8 +129,11 @@ public class Trust extends Command {
size += currentPlot.getMembers().contains(uuid) ? 0 : 1; size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
} }
checkTrue(!uuids.isEmpty(), null); checkTrue(!uuids.isEmpty(), null);
if (!(player.hasPermission("plots.trust." + size) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) int maxTrustSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_TRUST, Settings.Limit.MAX_PLOTS);
player.sendMessage(TranslatableCaption.of("members.plot_max_members"), Template.of("amount", String.valueOf(size - 1))); if (size > maxTrustSize) {
player.sendMessage(TranslatableCaption.of("members.plot_max_members_trusted"), Template.of("amount", String.valueOf(size - 1)));
return;
}
// Success // Success
confirm.run(this, () -> { confirm.run(this, () -> {
for (UUID uuid : uuids) { for (UUID uuid : uuids) {

View File

@ -78,6 +78,8 @@ public enum Permission {
PERMISSION_ADMIN_COMMAND_PURGE_RATINGS("plots.admin.command.purge.ratings"), PERMISSION_ADMIN_COMMAND_PURGE_RATINGS("plots.admin.command.purge.ratings"),
PERMISSION_ADMIN_COMMAND_ADD("plots.admin.command.trust"), PERMISSION_ADMIN_COMMAND_ADD("plots.admin.command.trust"),
PERMISSION_ADMIN_COMMAND_TRUST("plots.admin.command.trust"), PERMISSION_ADMIN_COMMAND_TRUST("plots.admin.command.trust"),
PERMISSION_TRUST("plots.trust"),
PERMISSION_ADD("plots.add"),
PERMISSION_TRUST_EVERYONE("plots.trust.everyone"), PERMISSION_TRUST_EVERYONE("plots.trust.everyone"),
PERMISSION_AREA_CREATE("plots.area.create"), PERMISSION_AREA_CREATE("plots.area.create"),
PERMISSION_AREA_INFO("plots.area.info"), PERMISSION_AREA_INFO("plots.area.info"),

View File

@ -452,7 +452,8 @@
"member.already_owner": "<prefix><gray><player></gray><gold> is already the plot owner.</gold>", "member.already_owner": "<prefix><gray><player></gray><gold> is already the plot owner.</gold>",
"member.already_added": "<prefix><gray>That user is already added to that category: <player></gray>", "member.already_added": "<prefix><gray>That user is already added to that category: <player></gray>",
"member.member_added": "<prefix><dark_aqua>That user can now build while the plot owner is online.</dark_aqua>", "member.member_added": "<prefix><dark_aqua>That user can now build while the plot owner is online.</dark_aqua>",
"members.plot_max_members": "<prefix><red>You are not allowed to add more than </red><gold><amount></gold><red> players to this plot.</red>", "members.plot_max_members_added": "<prefix><red>You are not allowed to add more than </red><gold><amount></gold><red> players to this plot.</red>",
"members.plot_max_members_trusted": "<prefix><red>You are not allowed to trust more than </red><gold><amount></gold><red> players to this plot.</red>",
"members.plot_max_members_denied": "<prefix><red>You are not allowed to deny more than </red><gold><amount></gold><red> players from this plot.</red>", "members.plot_max_members_denied": "<prefix><red>You are not allowed to deny more than </red><gold><amount></gold><red> players from this plot.</red>",
"members.not_added_trusted": "<prefix><red>You must be added or trusted to the plot to run that command.</red>", "members.not_added_trusted": "<prefix><red>You must be added or trusted to the plot to run that command.</red>",