mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Added placeholders replacement in BentoBox's own messages
It is now possible to use external placeholders into BentoBox's messages.
This commit is contained in:
parent
b4fe70da0c
commit
3f83a89215
@ -1,13 +1,5 @@
|
||||
package world.bentobox.bentobox.api.user;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -23,11 +15,18 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.events.OfflineMessageEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Combines {@link Player}, {@link OfflinePlayer} and {@link CommandSender} to provide convenience methods related to
|
||||
* localization and generic interactions.
|
||||
@ -348,6 +347,11 @@ public class User {
|
||||
}
|
||||
}
|
||||
|
||||
// Then replace Placeholders, this will only work if this is a player
|
||||
if (player != null) {
|
||||
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', translation);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package world.bentobox.bentobox.hooks;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
@ -103,4 +105,16 @@ public class PlaceholderAPIHook extends Hook {
|
||||
public boolean isPlaceholder(@NonNull Addon addon, @NonNull String placeholder) {
|
||||
return addonsExpansions.containsKey(addon) && addonsExpansions.get(addon).isPlaceholder(placeholder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the placeholders in this String and returns it.
|
||||
* @param player the Player to get the placeholders for.
|
||||
* @param string the String to replace the placeholders in.
|
||||
* @return the String with placeholders replaced, or the identical String if no placeholders were available.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@NonNull
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
@ -121,4 +122,19 @@ public class PlaceholdersManager {
|
||||
public boolean isPlaceholder(@NonNull Addon addon, @NonNull String placeholder) {
|
||||
return getPlaceholderAPIHook().map(h -> h.isPlaceholder(addon, placeholder)).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the placeholders in this String and returns it.
|
||||
* @param player the Player to get the placeholders for.
|
||||
* @param string the String to replace the placeholders in.
|
||||
* @return the String with placeholders replaced, or the identical String if no placeholders were available.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
if (getPlaceholderAPIHook().isPresent()) {
|
||||
string = getPlaceholderAPIHook().get().replacePlaceholders(player, string);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,6 @@
|
||||
*/
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -33,7 +21,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
@ -46,9 +33,22 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -140,8 +140,15 @@ public class IslandExpelCommandTest {
|
||||
when(island.getWorld()).thenReturn(mock(World.class));
|
||||
|
||||
// Locales
|
||||
when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(1, String.class));
|
||||
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
|
||||
when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer(answer);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(Mockito.any(), Mockito.any())).thenAnswer(answer);
|
||||
|
||||
// Class
|
||||
iec = new IslandExpelCommand(ic);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -119,6 +120,11 @@ public class IslandTeamKickCommandTest {
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
|
||||
// IWM friendly name
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
|
@ -1,21 +1,5 @@
|
||||
package world.bentobox.bentobox.api.user;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
@ -37,15 +21,31 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ BentoBox.class, Bukkit.class })
|
||||
@ -101,6 +101,11 @@ public class UserTest {
|
||||
when(lm.get(any(), any())).thenReturn(TEST_TRANSLATION);
|
||||
when(lm.get(any())).thenReturn(TEST_TRANSLATION);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn(TEST_TRANSLATION);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -1,19 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -28,15 +14,29 @@ import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.Notifier;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||
public class BannedVisitorCommandsTest {
|
||||
@ -89,6 +89,11 @@ public class BannedVisitorCommandsTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Notifier
|
||||
Notifier notifier = mock(Notifier.class);
|
||||
when(plugin.getNotifier()).thenReturn(notifier);
|
||||
|
@ -1,19 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -53,7 +39,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -65,8 +50,23 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -144,6 +144,11 @@ public class BreakBlocksListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -3,20 +3,6 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -45,7 +31,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -57,9 +42,24 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -158,6 +158,11 @@ public class BreedingListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Player name
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(pm.getName(Mockito.any())).thenReturn("tastybento");
|
||||
|
@ -1,19 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -41,7 +27,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -53,8 +38,23 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -131,6 +131,11 @@ public class BucketListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -1,18 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -34,7 +21,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -46,8 +32,22 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -124,6 +124,11 @@ public class EggListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -3,18 +3,6 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -35,7 +23,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -45,8 +32,21 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests the listener
|
||||
* @author tastybento
|
||||
@ -97,6 +97,11 @@ public class ExperiencePickupListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -3,16 +3,6 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -39,7 +29,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -51,8 +40,19 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -145,6 +145,11 @@ public class HurtingListenerTest {
|
||||
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Notifier
|
||||
notifier = mock(Notifier.class);
|
||||
when(plugin.getNotifier()).thenReturn(notifier);
|
||||
|
@ -1,20 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -50,7 +35,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -62,8 +46,24 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -143,6 +143,11 @@ public class InventoryListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -1,17 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -32,7 +20,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.user.Notifier;
|
||||
@ -42,8 +29,21 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class LockAndBanListenerTest {
|
||||
@ -123,6 +123,11 @@ public class LockAndBanListenerTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Notifier
|
||||
notifier = mock(Notifier.class);
|
||||
when(plugin.getNotifier()).thenReturn(notifier);
|
||||
|
@ -1,19 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -46,7 +32,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -58,9 +43,24 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -142,6 +142,11 @@ public class PhysicalInteractionListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Player name
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(pm.getName(Mockito.any())).thenReturn("tastybento");
|
||||
|
@ -3,20 +3,6 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -49,7 +35,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -61,8 +46,23 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -138,6 +138,11 @@ public class PlaceBlocksListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -1,20 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -48,7 +33,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -60,9 +44,25 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} )
|
||||
public class TNTListenerTest {
|
||||
@ -139,6 +139,11 @@ public class TNTListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Player name
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(pm.getName(Mockito.any())).thenReturn("tastybento");
|
||||
|
@ -3,20 +3,6 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -38,7 +24,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -50,8 +35,23 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -129,6 +129,11 @@ public class ThrowingListenerTest {
|
||||
Answer<String> answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
|
@ -3,22 +3,9 @@
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.settings;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -53,11 +40,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -72,8 +54,25 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -169,7 +168,13 @@ public class PVPListenerTest {
|
||||
// Locales - this returns the string that was requested for translation
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(1, String.class));
|
||||
Answer<String> answer = (Answer<String>) invocation -> invocation.getArgumentAt(1, String.class);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Create some entities
|
||||
zombie = mock(Zombie.class);
|
||||
|
@ -1,16 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -37,7 +26,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -49,8 +37,20 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({BentoBox.class, Util.class })
|
||||
public class EnderChestListenerTest {
|
||||
@ -122,7 +122,13 @@ public class EnderChestListenerTest {
|
||||
// Locales - this returns the string that was requested for translation
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(1, String.class));
|
||||
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
|
||||
when(lm.get(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Notifier
|
||||
notifier = mock(Notifier.class);
|
||||
|
@ -1,14 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -25,7 +16,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -36,9 +26,19 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -102,6 +102,11 @@ public class EnterExitListenerTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Notifier
|
||||
Notifier notifier = mock(Notifier.class);
|
||||
when(plugin.getNotifier()).thenReturn(notifier);
|
||||
|
@ -1,16 +1,5 @@
|
||||
package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -33,13 +22,24 @@ import org.mockito.Mockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({BentoBox.class, PlayerEvent.class, PlayerInteractEvent.class})
|
||||
@ -134,6 +134,11 @@ public class ObsidianScoopingListenerTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// World settings Flag
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
@ -267,7 +272,5 @@ public class ObsidianScoopingListenerTest {
|
||||
when(world.getBlockAt(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(airBlock);
|
||||
assertTrue(listener.onPlayerInteract(event));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,7 @@
|
||||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -50,10 +33,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
@ -65,6 +44,25 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.island.IslandCache;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { Bukkit.class, BentoBox.class, Util.class, Location.class })
|
||||
public class IslandsManagerTest {
|
||||
@ -124,6 +122,10 @@ public class IslandsManagerTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Placeholders
|
||||
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
|
Loading…
Reference in New Issue
Block a user