diff --git a/src/main/java/dev/espi/protectionstones/PSL.java b/src/main/java/dev/espi/protectionstones/PSL.java index 534d11f..afecfdf 100644 --- a/src/main/java/dev/espi/protectionstones/PSL.java +++ b/src/main/java/dev/espi/protectionstones/PSL.java @@ -90,6 +90,8 @@ public enum PSL { REMOVED_FROM_REGION("psregion.removed_from_region", ChatColor.AQUA + "%player%" + ChatColor.GRAY + " has been removed from region."), REMOVED_FROM_REGION_SPECIFIC("psregion.removed_from_region_specific", ChatColor.AQUA + "%player%" + ChatColor.GRAY + " has been removed from region %region%."), NOT_IN_REGION("psregion.not_in_region", ChatColor.RED + "You are not in a protection stones region!"), + MEMBERS_LIMIT("psregion.members_limit_reached", ChatColor.RED + "Members limit reached (%limit%) for region: %region%"), + OWNERS_LIMIT("psregion.owners_limit_reached", ChatColor.RED + "Owners limit reached (%limit%) for region: %region%"), PLAYER_NOT_FOUND("psregion.player_not_found", ChatColor.RED + "Player not found."), NOT_PS_REGION("psregion.not_ps_region", ChatColor.RED + "Not a protection stones region."), REGION_DOES_NOT_EXIST("psregion.region_does_not_exist", ChatColor.RED + "Region does not exist."), diff --git a/src/main/java/dev/espi/protectionstones/commands/ArgAddRemove.java b/src/main/java/dev/espi/protectionstones/commands/ArgAddRemove.java index b6f167e..bb4d024 100644 --- a/src/main/java/dev/espi/protectionstones/commands/ArgAddRemove.java +++ b/src/main/java/dev/espi/protectionstones/commands/ArgAddRemove.java @@ -16,7 +16,11 @@ package dev.espi.protectionstones.commands; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import dev.espi.protectionstones.*; +import dev.espi.protectionstones.PSGroupRegion; +import dev.espi.protectionstones.PSL; +import dev.espi.protectionstones.PSPlayer; +import dev.espi.protectionstones.PSRegion; +import dev.espi.protectionstones.ProtectionStones; import dev.espi.protectionstones.utils.LimitUtil; import dev.espi.protectionstones.utils.UUIDCache; import dev.espi.protectionstones.utils.WGUtils; @@ -25,7 +29,13 @@ import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -119,12 +129,33 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap atm if more than one owner + // then, if a second owner has perm with more members/owners, he can add them - possible abuse? + int membersLimit = LimitUtil.getPermissionIntVariable(p, "protectionstones.members-limit.", 2, 0); + int ownersLimit = LimitUtil.getPermissionIntVariable(p, "protectionstones.owners-limit.", 2, 1); + + if (operationType.equals("add") && r.getMembers().size() >= membersLimit) { + PSL.msg(p, PSL.MEMBERS_LIMIT.msg() + .replace("%limit%", String.valueOf(membersLimit)) + .replace("%region%", regionName)); + continue; + } + if (operationType.equals("addowner") && r.getOwners().size() >= ownersLimit) { + PSL.msg(p, PSL.OWNERS_LIMIT.msg() + .replace("%limit%", String.valueOf(ownersLimit)) + .replace("%region%", regionName)); + continue; + } + if (flags.containsKey("-a")) { PSL.msg(p, PSL.ADDED_TO_REGION_SPECIFIC.msg() .replace("%player%", addPlayerName) - .replace("%region%", r.getName() == null ? r.getId() : r.getName() + " (" + r.getId() + ")")); + .replace("%region%", regionName)); } else { + PSL.msg(p, PSL.ADDED_TO_REGION.msg().replace("%player%", addPlayerName)); } @@ -137,7 +168,7 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap perm = player.getEffectivePermissions().stream() + .filter(p -> p.getPermission().startsWith(searchingPerm)).findFirst(); + if (perm.isEmpty()) { + return defaultValue; + } + //getting var perm + String[] split = perm.get().getPermission().split("\\."); + if (split.length < varPos + 1) { + return defaultValue; + } + String limitString = split[varPos]; + + if (NumberUtils.isNumber(limitString)) { + return Integer.parseInt(limitString); + } + return defaultValue; + } + }