Skip to content

Commit

Permalink
Fix for console error when using the player command in console
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 9, 2019
1 parent e6fd6e0 commit 21fd9e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +48,8 @@ public class CustomIslandMultiHomeHelpTest {
@Mock
private User user;
private CustomIslandMultiHomeHelp ch;
@Mock
private IslandWorldManager iwm;

/**
* @throws java.lang.Exception
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -194,5 +198,5 @@ public void testExecuteUserStringListOfStringMaxHomes() {
"description"
);
}

}
14 changes: 12 additions & 2 deletions src/test/java/world/bentobox/bentobox/api/user/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)}
Expand Down

0 comments on commit 21fd9e9

Please sign in to comment.