Entity limits are now counted to include nether and end.
https://github.com/BentoBoxWorld/Limits/issues/43
This commit is contained in:
parent
25be7a3844
commit
f907784bd7
2
pom.xml
2
pom.xml
|
@ -64,7 +64,7 @@
|
|||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>1.9.0</build.version>
|
||||
<build.version>1.9.1</build.version>
|
||||
</properties>
|
||||
|
||||
<!-- Profiles will allow to automatically change build version. -->
|
||||
|
|
|
@ -89,6 +89,7 @@ public class LimitPanel {
|
|||
user.sendMessage("island.limits.no-limits");
|
||||
return;
|
||||
}
|
||||
// Material limits
|
||||
for (Entry<Material, Integer> en : matLimits.entrySet()) {
|
||||
PanelItemBuilder pib = new PanelItemBuilder();
|
||||
pib.name(Util.prettifyText(en.getKey().toString()));
|
||||
|
@ -103,6 +104,7 @@ public class LimitPanel {
|
|||
"[limit]", String.valueOf(en.getValue())));
|
||||
pb.item(pib.build());
|
||||
}
|
||||
// Entity limits
|
||||
addon.getSettings().getLimits().forEach((k,v) -> {
|
||||
PanelItemBuilder pib = new PanelItemBuilder();
|
||||
pib.name(Util.prettifyText(k.toString()));
|
||||
|
@ -131,9 +133,22 @@ public class LimitPanel {
|
|||
pb.build();
|
||||
}
|
||||
|
||||
private long getCount(Island island, EntityType ent) {
|
||||
return island.getWorld().getEntities().stream()
|
||||
long getCount(Island island, EntityType ent) {
|
||||
long count = island.getWorld().getEntities().stream()
|
||||
.filter(e -> e.getType().equals(ent))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
// Nether
|
||||
if (addon.getPlugin().getIWM().isNetherIslands(island.getWorld())) {
|
||||
count += addon.getPlugin().getIWM().getNetherWorld(island.getWorld()).getEntities().stream()
|
||||
.filter(e -> e.getType().equals(ent))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
}
|
||||
// End
|
||||
if (addon.getPlugin().getIWM().isEndIslands(island.getWorld())) {
|
||||
count += addon.getPlugin().getIWM().getEndWorld(island.getWorld()).getEntities().stream()
|
||||
.filter(e -> e.getType().equals(ent))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package world.bentobox.limits.commands;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.limits.Limits;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( Bukkit.class )
|
||||
public class LimitPanelTest {
|
||||
|
||||
@Mock
|
||||
private Limits addon;
|
||||
|
||||
private LimitPanel lp;
|
||||
|
||||
@Mock
|
||||
private Island island;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private World nether;
|
||||
@Mock
|
||||
private World end;
|
||||
@Mock
|
||||
private BentoBox plugin;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Island
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
// Addon
|
||||
when(addon.getPlugin()).thenReturn(plugin);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.isNetherIslands(any())).thenReturn(true);
|
||||
when(iwm.isEndIslands(any())).thenReturn(true);
|
||||
when(iwm.getNetherWorld(eq(world))).thenReturn(nether);
|
||||
when(iwm.getEndWorld(eq(world))).thenReturn(end);
|
||||
// Worlds
|
||||
Entity entity = mock(Entity.class);
|
||||
when(entity.getType()).thenReturn(EntityType.BAT);
|
||||
when(entity.getLocation()).thenReturn(mock(Location.class));
|
||||
when(world.getEntities()).thenReturn(Collections.singletonList(entity));
|
||||
when(nether.getEntities()).thenReturn(Collections.singletonList(entity));
|
||||
when(end.getEntities()).thenReturn(Collections.singletonList(entity));
|
||||
lp = new LimitPanel(addon);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testShowLimits() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCountInIslandSpace() {
|
||||
when(island.inIslandSpace(any(Location.class))).thenReturn(true);
|
||||
EntityType ent = EntityType.BAT;
|
||||
assertEquals(3L, lp.getCount(island, ent));
|
||||
ent = EntityType.GHAST;
|
||||
assertEquals(0L, lp.getCount(island, ent));
|
||||
when(iwm.isEndIslands(any())).thenReturn(false);
|
||||
ent = EntityType.BAT;
|
||||
assertEquals(2L, lp.getCount(island, ent));
|
||||
when(iwm.isNetherIslands(any())).thenReturn(false);
|
||||
ent = EntityType.BAT;
|
||||
assertEquals(1L, lp.getCount(island, ent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCountNotInIslandSpace() {
|
||||
EntityType ent = EntityType.BAT;
|
||||
assertEquals(0L, lp.getCount(island, ent));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue