mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-29 12:37:37 +01:00
Fixes chunk deletion bug and corrects chunk calculations elsewhere.
https://github.com/BentoBoxWorld/bentobox/issues/405 Adds test class for DeleteIslandChunks class.
This commit is contained in:
parent
8da55b6e21
commit
a7365ef805
@ -33,7 +33,7 @@ public class CleanSuperFlatListener extends FlagListener {
|
||||
return;
|
||||
}
|
||||
world.regenerateChunk(e.getChunk().getX(), e.getChunk().getZ());
|
||||
plugin.logWarning("Regenerating superflat chunk in " + world.getName() + " at blocks " + (e.getChunk().getX() * 16) + "," + (e.getChunk().getZ() * 16));
|
||||
plugin.logWarning("Regenerating superflat chunk in " + world.getName() + " at blocks " + (e.getChunk().getX() << 4) + "," + (e.getChunk().getZ() << 4));
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,13 +32,14 @@ public class DeleteIslandChunks {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int minXChunk = island.getMinX() / 16;
|
||||
int maxXChunk = (island.getRange() * 2 + island.getMinX() - 1) /16;
|
||||
int minZChunk = island.getMinZ() / 16;
|
||||
int maxZChunk = (island.getRange() * 2 + island.getMinZ() - 1) /16;
|
||||
int minXChunk = island.getMinX() >> 4;
|
||||
int maxXChunk = (island.getRange() * 2 + island.getMinX() - 1) >> 4;
|
||||
int minZChunk = island.getMinZ() >> 4;
|
||||
int maxZChunk = (island.getRange() * 2 + island.getMinZ() - 1) >> 4;
|
||||
for (int x = minXChunk; x <= maxXChunk; x++) {
|
||||
for (int z = minZChunk; z<=maxZChunk; z++) {
|
||||
world.regenerateChunk(x, z);
|
||||
//System.out.println("regenerating = " + x + "," + z);
|
||||
if (plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world)) {
|
||||
plugin.getIWM().getNetherWorld(world).regenerateChunk(x, z);
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class SafeSpotTeleport {
|
||||
do {
|
||||
for (int i = x - radius; i <= x + radius; i+=16) {
|
||||
for (int j = z - radius; j <= z + radius; j+=16) {
|
||||
addChunk(result, island, new Pair<>(i,j), new Pair<>(i/16, j/16));
|
||||
addChunk(result, island, new Pair<>(i,j), new Pair<>(i >> 4, j >> 4));
|
||||
}
|
||||
}
|
||||
radius++;
|
||||
@ -301,7 +301,7 @@ public class SafeSpotTeleport {
|
||||
}
|
||||
|
||||
private boolean safe(ChunkSnapshot chunk, int x, int y, int z, World world) {
|
||||
Vector newSpot = new Vector(chunk.getX() * 16 + x + 0.5D, y + 1, chunk.getZ() * 16 + z + 0.5D);
|
||||
Vector newSpot = new Vector((chunk.getX() << 4) + x + 0.5D, y + 1, (chunk.getZ() << 4) + z + 0.5D);
|
||||
if (portal) {
|
||||
if (bestSpot == null) {
|
||||
// Stash the best spot
|
||||
|
@ -0,0 +1,152 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.util;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests the island delete class
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class})
|
||||
public class DeleteIslandChunksTest {
|
||||
|
||||
private BentoBox plugin;
|
||||
private Island island;
|
||||
private Location location;
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
plugin = mock(BentoBox.class);
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
// No Nether or End by default
|
||||
when(iwm.isNetherGenerate(Mockito.any())).thenReturn(false);
|
||||
when(iwm.isNetherIslands(Mockito.any())).thenReturn(false);
|
||||
when(iwm.isEndGenerate(Mockito.any())).thenReturn(false);
|
||||
when(iwm.isEndIslands(Mockito.any())).thenReturn(false);
|
||||
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
// World
|
||||
//world = mock(World.class, Mockito.withSettings().verboseLogging());
|
||||
world = mock(World.class);
|
||||
|
||||
island = new Island();
|
||||
island.setRange(64);
|
||||
|
||||
location = mock(Location.class);
|
||||
|
||||
when(location.getWorld()).thenReturn(world);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.util.DeleteIslandChunks#DeleteIslandChunks(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.database.objects.Island)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testDeleteIslandChunksNegativeX() {
|
||||
|
||||
// Island adjacent to an island at 0,0
|
||||
Location location2 = mock(Location.class);
|
||||
|
||||
when(location2.getWorld()).thenReturn(world);
|
||||
when(location2.getBlockX()).thenReturn(-128);
|
||||
when(location2.getBlockY()).thenReturn(120);
|
||||
when(location2.getBlockZ()).thenReturn(0);
|
||||
island.setCenter(location2);
|
||||
|
||||
new DeleteIslandChunks(plugin, island);
|
||||
Mockito.verify(world, Mockito.times(64)).regenerateChunk(Mockito.anyInt(), Mockito.anyInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.util.DeleteIslandChunks#DeleteIslandChunks(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.database.objects.Island)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testDeleteIslandChunksNegativeXX() {
|
||||
|
||||
// Island adjacent to an island at 0,0
|
||||
Location location2 = mock(Location.class);
|
||||
|
||||
when(location2.getWorld()).thenReturn(world);
|
||||
when(location2.getBlockX()).thenReturn(-256);
|
||||
when(location2.getBlockY()).thenReturn(120);
|
||||
when(location2.getBlockZ()).thenReturn(0);
|
||||
island.setCenter(location2);
|
||||
|
||||
new DeleteIslandChunks(plugin, island);
|
||||
Mockito.verify(world, Mockito.times(64)).regenerateChunk(Mockito.anyInt(), Mockito.anyInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.util.DeleteIslandChunks#DeleteIslandChunks(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.database.objects.Island)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testDeleteIslandChunksIslandPositiveX() {
|
||||
|
||||
// Island adjacent to an island at 0,0
|
||||
Location location2 = mock(Location.class);
|
||||
|
||||
when(location2.getWorld()).thenReturn(world);
|
||||
when(location2.getBlockX()).thenReturn(0);
|
||||
when(location2.getBlockY()).thenReturn(120);
|
||||
when(location2.getBlockZ()).thenReturn(0);
|
||||
island.setCenter(location2);
|
||||
|
||||
new DeleteIslandChunks(plugin, island);
|
||||
Mockito.verify(world, Mockito.times(64)).regenerateChunk(Mockito.anyInt(), Mockito.anyInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.util.DeleteIslandChunks#DeleteIslandChunks(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.database.objects.Island)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testDeleteIslandChunksPositiveXX() {
|
||||
|
||||
// Island adjacent to an island at 0,0
|
||||
Location location2 = mock(Location.class);
|
||||
|
||||
when(location2.getWorld()).thenReturn(world);
|
||||
when(location2.getBlockX()).thenReturn(256);
|
||||
when(location2.getBlockY()).thenReturn(120);
|
||||
when(location2.getBlockZ()).thenReturn(0);
|
||||
island.setCenter(location2);
|
||||
|
||||
new DeleteIslandChunks(plugin, island);
|
||||
Mockito.verify(world, Mockito.times(64)).regenerateChunk(Mockito.anyInt(), Mockito.anyInt());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user