Fix for console error when using the player command in console

https://github.com/BentoBoxWorld/BentoBox/issues/886
This commit is contained in:
tastybento 2019-08-09 14:08:21 -07:00
parent e6fd6e02b7
commit 21fd9e9e1a
3 changed files with 24 additions and 7 deletions

View File

@ -291,6 +291,9 @@ public class User {
* @return max value
*/
public int getPermissionValue(String permissionPrefix, int defaultValue) {
// If requester is console, then return the default value
if (!isPlayer()) return defaultValue;
int value = defaultValue;
// If there is a dot at the end of the permissionPrefix, remove it

View File

@ -3,11 +3,11 @@ package world.bentobox.bentobox.api.commands.island;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
@ -48,6 +48,8 @@ public class CustomIslandMultiHomeHelpTest {
@Mock
private User user;
private CustomIslandMultiHomeHelp ch;
@Mock
private IslandWorldManager iwm;
/**
* @throws java.lang.Exception
@ -106,9 +108,11 @@ public class CustomIslandMultiHomeHelpTest {
when(Bukkit.getScheduler()).thenReturn(sch);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
// Locales
// Command
ch = new CustomIslandMultiHomeHelp(ic);
@ -194,5 +198,5 @@ public class CustomIslandMultiHomeHelpTest {
"description"
);
}
}

View File

@ -5,8 +5,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -481,6 +481,16 @@ public class UserTest {
assertEquals(33, u.getPermissionValue("bskyblock.max", 2));
}
/**
* Test for {@link User#getPermissionValue(String, int)}
*/
@Test
public void testGetPermissionValueConsole() {
User.clearUsers();
CommandSender console = mock(CommandSender.class);
User u = User.getInstance(console);
assertEquals(35, u.getPermissionValue("bskyblock.max", 35));
}
/**
* Test for {@link User#getPermissionValue(String, int)}