From 21fd9e9e1a7eff7b32c568447824b06a8a8687e2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 9 Aug 2019 14:08:21 -0700 Subject: [PATCH] Fix for console error when using the player command in console https://github.com/BentoBoxWorld/BentoBox/issues/886 --- .../world/bentobox/bentobox/api/user/User.java | 3 +++ .../island/CustomIslandMultiHomeHelpTest.java | 14 +++++++++----- .../world/bentobox/bentobox/api/user/UserTest.java | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index 5fa729e2f..ba0dc489f 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -291,6 +291,9 @@ public boolean isOp() { * @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 diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/CustomIslandMultiHomeHelpTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/CustomIslandMultiHomeHelpTest.java index cb98a092d..c53adbb9f 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/CustomIslandMultiHomeHelpTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/CustomIslandMultiHomeHelpTest.java @@ -3,11 +3,11 @@ 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 void setUp() throws Exception { 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 void testExecuteUserStringListOfStringMaxHomes() { "description" ); } - + } diff --git a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java index de86d3c42..68b1f9005 100644 --- a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java +++ b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java @@ -5,8 +5,8 @@ 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 void testGetPermissionValue() { 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)}