mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Added sum deaths setting support.
Other items WIP https://github.com/BentoBoxWorld/BentoBox/issues/738
This commit is contained in:
parent
899315b437
commit
f0baeece3d
@ -280,4 +280,22 @@ public interface WorldSettings extends ConfigObject {
|
||||
* @return the ban limit for this world.
|
||||
*/
|
||||
int getBanLimit();
|
||||
|
||||
/**
|
||||
* @return whether leavers should lose a reset or not
|
||||
*/
|
||||
boolean isLeaversLoseReset();
|
||||
|
||||
/**
|
||||
* @return whether players keep their inventory if they are kicked or not
|
||||
*/
|
||||
boolean isKickedKeepInventory();
|
||||
|
||||
|
||||
/**
|
||||
* @return whether the death value reported by {@link world.bentobox.bentobox.database.objects.Players#getDeaths()}
|
||||
* should include a sum of all players on the island or not
|
||||
*/
|
||||
boolean isDeathsSumTeam();
|
||||
|
||||
}
|
||||
|
@ -266,12 +266,22 @@ public class Players implements DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of deaths in this world
|
||||
* Get the number of deaths in this world. If {@link world.bentobox.bentobox.api.configuration.WorldSettings#isDeathsSumTeam()}
|
||||
* is true, then this value will be the sum of the team deaths.
|
||||
* @param world - world
|
||||
* @return number of deaths
|
||||
*/
|
||||
public int getDeaths(World world) {
|
||||
return deaths.getOrDefault(world.getName(), 0);
|
||||
BentoBox plugin = BentoBox.getInstance();
|
||||
int d = deaths.getOrDefault(world.getName(), 0);
|
||||
if (plugin.getIWM().isDeathsSumTeam(world) && plugin.getIslands().hasIsland(world, getPlayerUUID())) {
|
||||
// Sum team deaths
|
||||
d += plugin.getIslands().getIsland(world, getPlayerUUID()).getMemberSet().stream()
|
||||
.filter(playerUUID -> !getPlayerUUID().equals(playerUUID))
|
||||
.map(playerUUID -> plugin.getPlayers().getDeaths(world, playerUUID))
|
||||
.collect(Collectors.summingInt(Integer::intValue));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,13 @@
|
||||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
@ -9,20 +17,13 @@ import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Handles registration and management of worlds
|
||||
*
|
||||
@ -691,7 +692,34 @@ public class IslandWorldManager {
|
||||
return gameModes.get(world).getWorldSettings().getDeathsMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ban limit for this world
|
||||
* @param world - world
|
||||
* @return ban limit
|
||||
*/
|
||||
public int getBanLimit(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getBanLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether leavers should lose a reset or not
|
||||
*/
|
||||
public boolean isLeaversLoseReset(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isLeaversLoseReset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether players keep their inventory if they are kicked or not
|
||||
*/
|
||||
public boolean isKickedKeepInventory(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isKickedKeepInventory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the death value reported by {@link world.bentobox.bentobox.database.objects.Players#getDeaths()}
|
||||
* should include a sum of all players on the island or not
|
||||
*/
|
||||
public boolean isDeathsSumTeam(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isDeathsSumTeam();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
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;
|
||||
|
||||
@ -17,31 +18,44 @@ import org.bukkit.World;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
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 world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class})
|
||||
public class PlayersTest {
|
||||
|
||||
@Mock
|
||||
private BentoBox plugin;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
private Players p;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
IslandWorldManager s = mock(IslandWorldManager.class);
|
||||
|
||||
when(s.getDeathsMax(Mockito.any())).thenReturn(3);
|
||||
when(plugin.getIWM()).thenReturn(s);
|
||||
when(iwm.getDeathsMax(Mockito.any())).thenReturn(3);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
Server server = mock(Server.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
@ -52,9 +66,29 @@ public class PlayersTest {
|
||||
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
|
||||
when(Bukkit.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
|
||||
|
||||
}
|
||||
// world
|
||||
when(world.getName()).thenReturn("world");
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
||||
private BentoBox plugin;
|
||||
// Island manager
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
Island island = mock(Island.class);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID uuid2 = UUID.randomUUID();
|
||||
UUID uuid3 = UUID.randomUUID();
|
||||
ImmutableSet<UUID> set = ImmutableSet.of(uuid, uuid2, uuid3);
|
||||
when(island.getMemberSet()).thenReturn(set);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Player manager
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(pm.getDeaths(any(), any())).thenReturn(25);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Player
|
||||
p = new Players(plugin, uuid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayersBSkyBlockUUID() {
|
||||
@ -63,24 +97,17 @@ public class PlayersTest {
|
||||
|
||||
@Test
|
||||
public void testSetHomeLocationLocation() {
|
||||
Players p = new Players(plugin, UUID.randomUUID());
|
||||
Location l = mock(Location.class);
|
||||
World w = mock(World.class);
|
||||
when(w.getName()).thenReturn("world");
|
||||
when(w.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
when(l.getWorld()).thenReturn(w);
|
||||
when(l.getWorld()).thenReturn(world);
|
||||
p.setHomeLocation(l, 5);
|
||||
assertEquals(l, p.getHomeLocation(w, 5));
|
||||
assertNotEquals(l, p.getHomeLocation(w, 0));
|
||||
p.clearHomeLocations(w);
|
||||
assertTrue(p.getHomeLocations(w).isEmpty());
|
||||
assertEquals(l, p.getHomeLocation(world, 5));
|
||||
assertNotEquals(l, p.getHomeLocation(world, 0));
|
||||
p.clearHomeLocations(world);
|
||||
assertTrue(p.getHomeLocations(world).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeaths() {
|
||||
Players p = new Players(plugin, UUID.randomUUID());
|
||||
World world = mock(World.class);
|
||||
when(world.getName()).thenReturn("world_name");
|
||||
assertTrue(p.getDeaths(world) == 0);
|
||||
p.addDeath(world);
|
||||
assertTrue(p.getDeaths(world) == 1);
|
||||
@ -98,4 +125,37 @@ public class PlayersTest {
|
||||
assertTrue(p.getDeaths(world) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link world.bentobox.bentobox.database.objects.Players#getDeaths(World)}
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeathsNoSumTeam() {
|
||||
p.addDeath(world);
|
||||
p.addDeath(world);
|
||||
assertEquals(2, p.getDeaths(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link world.bentobox.bentobox.database.objects.Players#getDeaths(World)}
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeathsSumTeamNoIsland() {
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
p.addDeath(world);
|
||||
p.addDeath(world);
|
||||
when(iwm.isDeathsSumTeam(any())).thenReturn(true);
|
||||
assertEquals(2, p.getDeaths(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link world.bentobox.bentobox.database.objects.Players#getDeaths(World)}
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeathsSumTeamHasIsland() {
|
||||
p.addDeath(world);
|
||||
p.addDeath(world);
|
||||
when(iwm.isDeathsSumTeam(any())).thenReturn(true);
|
||||
assertEquals(52, p.getDeaths(world));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user