mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-12 10:21:46 +01:00
Replaced Util#getPermValue(Player, String, int) with User#getPermissionValue(String, int)
This commit is contained in:
parent
3102195156
commit
95bfab916e
@ -4,7 +4,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command.
|
* This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command.
|
||||||
@ -12,7 +11,6 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
* This is an example of a custom help as much as anything.
|
* This is an example of a custom help as much as anything.
|
||||||
*
|
*
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
||||||
|
|
||||||
@ -47,7 +45,7 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
|||||||
private void showPrettyHelp(User user, String usage, String params, String desc) {
|
private void showPrettyHelp(User user, String usage, String params, String desc) {
|
||||||
// Player. Check perms
|
// Player. Check perms
|
||||||
if (user.hasPermission(getPermission())) {
|
if (user.hasPermission(getPermission())) {
|
||||||
int maxHomes = Util.getPermValue(user.getPlayer(), getPermissionPrefix() + "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
int maxHomes = user.getPermissionValue(getPermissionPrefix() + "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||||
if (maxHomes > 1) {
|
if (maxHomes > 1) {
|
||||||
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
|
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import org.apache.commons.lang.math.NumberUtils;
|
|||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -34,7 +33,7 @@ public class IslandGoCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) {
|
if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) {
|
||||||
int homeValue = Integer.parseInt(args.get(0));
|
int homeValue = Integer.parseInt(args.get(0));
|
||||||
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
int maxHomes = user.getPermissionValue("island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||||
if (homeValue > 1 && homeValue <= maxHomes) {
|
if (homeValue > 1 && homeValue <= maxHomes) {
|
||||||
getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue);
|
getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue);
|
||||||
user.sendMessage("commands.island.go.tip", TextVariables.LABEL, getTopLabel());
|
user.sendMessage("commands.island.go.tip", TextVariables.LABEL, getTopLabel());
|
||||||
|
@ -6,7 +6,6 @@ import java.util.UUID;
|
|||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
|
|
||||||
public class IslandSethomeCommand extends CompositeCommand {
|
public class IslandSethomeCommand extends CompositeCommand {
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.sethome.home-set");
|
user.sendMessage("commands.island.sethome.home-set");
|
||||||
} else {
|
} else {
|
||||||
// Dynamic home sizes with permissions
|
// Dynamic home sizes with permissions
|
||||||
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
int maxHomes = user.getPermissionValue("island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||||
if (maxHomes > 1) {
|
if (maxHomes > 1) {
|
||||||
// Check the number given is a number
|
// Check the number given is a number
|
||||||
int number;
|
int number;
|
||||||
|
@ -151,7 +151,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
* @return max team size of user
|
* @return max team size of user
|
||||||
*/
|
*/
|
||||||
public int getMaxTeamSize(User user) {
|
public int getMaxTeamSize(User user) {
|
||||||
return Util.getPermValue(user.getPlayer(), getPermissionPrefix() + "team.maxsize.", getIWM().getMaxTeamSize(getWorld()));
|
return user.getPermissionValue(getPermissionPrefix() + "team.maxsize.", getIWM().getMaxTeamSize(getWorld()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -182,6 +183,38 @@ public class User {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum value of a numerical permission setting
|
||||||
|
* @param permissionPrefix the start of the perm, e.g., bskyblock.maxhomes
|
||||||
|
* @param defaultValue the default value; the result may be higher or lower than this
|
||||||
|
* @return max value
|
||||||
|
*/
|
||||||
|
public int getPermissionValue(String permissionPrefix, int defaultValue) {
|
||||||
|
int value = defaultValue;
|
||||||
|
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||||
|
if (perms.getPermission().startsWith(permissionPrefix + ".")) {
|
||||||
|
// Get the max value should there be more than one
|
||||||
|
if (perms.getPermission().contains(permissionPrefix + ".*")) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
String[] spl = perms.getPermission().split(permissionPrefix + ".");
|
||||||
|
if (spl.length > 1) {
|
||||||
|
if (!NumberUtils.isDigits(spl[1])) {
|
||||||
|
plugin.logError("Player " + player.getName() + " has permission: '" + perms.getPermission() + "' <-- the last part MUST be a number! Ignoring...");
|
||||||
|
} else {
|
||||||
|
value = Math.max(value, Integer.valueOf(spl[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do some sanity checking
|
||||||
|
if (value < 1) {
|
||||||
|
value = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a translation of this reference for this user.
|
* Gets a translation of this reference for this user.
|
||||||
* @param reference - reference found in a locale file
|
* @param reference - reference found in a locale file
|
||||||
|
@ -792,7 +792,7 @@ public class IslandsManager {
|
|||||||
target.sendMessage("commands.island.team.setowner.you-are-the-owner");
|
target.sendMessage("commands.island.team.setowner.you-are-the-owner");
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
// Check if new leader has a different range permission than the island size
|
// Check if new leader has a different range permission than the island size
|
||||||
int range = Util.getPermValue(target.getPlayer(), permPrefix + "island.range.", plugin.getIWM().getIslandProtectionRange(Util.getWorld(island.getWorld())));
|
int range = target.getPermissionValue(permPrefix + "island.range", plugin.getIWM().getIslandProtectionRange(Util.getWorld(island.getWorld())));
|
||||||
// Range can go up or down
|
// Range can go up or down
|
||||||
if (range != island.getProtectionRange()) {
|
if (range != island.getProtectionRange()) {
|
||||||
user.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
|
user.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
|
||||||
@ -801,7 +801,6 @@ public class IslandsManager {
|
|||||||
+ range + " for " + user.getName() + " due to permission.");
|
+ range + " for " + user.getName() + " due to permission.");
|
||||||
}
|
}
|
||||||
island.setProtectionRange(range);
|
island.setProtectionRange(range);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,44 +172,10 @@ public class Util {
|
|||||||
return returned;
|
return returned;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the maximum value of a numerical perm setting
|
|
||||||
* @param player - the player - the player to check
|
|
||||||
* @param perm - the start of the perm, e.g., bskyblock.maxhomes
|
|
||||||
* @param permValue - the default value - the result may be higher or lower than this
|
|
||||||
* @return max value
|
|
||||||
*/
|
|
||||||
public static int getPermValue(Player player, String perm, int permValue) {
|
|
||||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
|
||||||
if (perms.getPermission().startsWith(perm + ".")) {
|
|
||||||
// Get the max value should there be more than one
|
|
||||||
if (perms.getPermission().contains(perm + ".*")) {
|
|
||||||
return permValue;
|
|
||||||
} else {
|
|
||||||
String[] spl = perms.getPermission().split(perm + ".");
|
|
||||||
if (spl.length > 1) {
|
|
||||||
if (!NumberUtils.isDigits(spl[1])) {
|
|
||||||
plugin.logError("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
permValue = Math.max(permValue, Integer.valueOf(spl[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Do some sanity checking
|
|
||||||
if (permValue < 1) {
|
|
||||||
permValue = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return permValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String xyz(Vector location) {
|
public static String xyz(Vector location) {
|
||||||
return location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ();
|
return location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks is world = world2 irrespective of the world type
|
* Checks is world = world2 irrespective of the world type
|
||||||
* @param world - world
|
* @param world - world
|
||||||
|
@ -113,7 +113,7 @@ public class IslandGoCommandTest {
|
|||||||
// Number of homes
|
// Number of homes
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
// 1 home for now
|
// 1 home for now
|
||||||
when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(1);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +125,6 @@ public class IslandGoCommandTest {
|
|||||||
IslandGoCommand igc = new IslandGoCommand(ic);
|
IslandGoCommand igc = new IslandGoCommand(ic);
|
||||||
assertFalse(igc.execute(user, igc.getLabel(), new ArrayList<>()));
|
assertFalse(igc.execute(user, igc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("general.errors.no-island");
|
Mockito.verify(user).sendMessage("general.errors.no-island");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +143,7 @@ public class IslandGoCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecuteNoArgsMultipleHomes() {
|
public void testExecuteNoArgsMultipleHomes() {
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
||||||
IslandGoCommand igc = new IslandGoCommand(ic);
|
IslandGoCommand igc = new IslandGoCommand(ic);
|
||||||
assertTrue(igc.execute(user, igc.getLabel(), new ArrayList<>()));
|
assertTrue(igc.execute(user, igc.getLabel(), new ArrayList<>()));
|
||||||
}
|
}
|
||||||
@ -155,7 +154,7 @@ public class IslandGoCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecuteArgs1MultipleHomes() {
|
public void testExecuteArgs1MultipleHomes() {
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
||||||
IslandGoCommand igc = new IslandGoCommand(ic);
|
IslandGoCommand igc = new IslandGoCommand(ic);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("1");
|
args.add("1");
|
||||||
@ -168,7 +167,7 @@ public class IslandGoCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecuteArgs2MultipleHomes() {
|
public void testExecuteArgs2MultipleHomes() {
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
||||||
IslandGoCommand igc = new IslandGoCommand(ic);
|
IslandGoCommand igc = new IslandGoCommand(ic);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("2");
|
args.add("2");
|
||||||
@ -183,7 +182,7 @@ public class IslandGoCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecuteArgsJunkMultipleHomes() {
|
public void testExecuteArgsJunkMultipleHomes() {
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(3);
|
||||||
IslandGoCommand igc = new IslandGoCommand(ic);
|
IslandGoCommand igc = new IslandGoCommand(ic);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("sdfsdf");
|
args.add("sdfsdf");
|
||||||
|
@ -152,7 +152,6 @@ public class PlayersManagerTest {
|
|||||||
.sorted(Comparator.reverseOrder())
|
.sorted(Comparator.reverseOrder())
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.forEach(File::delete);
|
.forEach(File::delete);
|
||||||
System.out.println(file.exists());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user