mirror of
https://github.com/BentoBoxWorld/BSkyBlock.git
synced 2024-12-26 17:07:41 +01:00
MC 1.21.3 update
This commit is contained in:
parent
4911e3b7c8
commit
b3c0123acb
14
pom.xml
14
pom.xml
@ -42,13 +42,9 @@
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>codemc-snapshots</id>
|
||||
<url>https://repo.codemc.org/repository/maven-snapshots</url>
|
||||
<id>codemc</id>
|
||||
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>codemc-releases</id>
|
||||
<url>https://repo.codemc.org/repository/maven-releases</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
@ -58,8 +54,8 @@
|
||||
<!-- Non-minecraft related dependencies -->
|
||||
<powermock.version>2.0.9</powermock.version>
|
||||
<!-- More visible way how to change dependency versions -->
|
||||
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>2.5.0-SNAPSHOT</bentobox.version>
|
||||
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>2.7.1-SNAPSHOT</bentobox.version>
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
<!-- Do not change unless you want different name for local builds. -->
|
||||
@ -121,7 +117,7 @@
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc</id>
|
||||
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
|
||||
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
|
@ -155,7 +155,7 @@ public class Settings implements WorldSettings {
|
||||
private Biome defaultBiome = Biome.PLAINS;
|
||||
@ConfigComment("The default biome for the nether world (this may affect what mobs can spawn)")
|
||||
@ConfigEntry(path = "world.default-nether-biome")
|
||||
private Biome defaultNetherBiome = Enums.getIfPresent(Biome.class, "NETHER").or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.BADLANDS));
|
||||
private Biome defaultNetherBiome = Biome.NETHER_WASTES;
|
||||
@ConfigComment("The default biome for the end world (this may affect what mobs can spawn)")
|
||||
@ConfigEntry(path = "world.default-end-biome")
|
||||
private Biome defaultEndBiome = Biome.THE_END;
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: BSkyBlock
|
||||
main: world.bentobox.bskyblock.BSkyBlock
|
||||
version: ${version}${build.number}
|
||||
api-version: 2.3.0
|
||||
api-version: 2.7.1
|
||||
metrics: true
|
||||
icon: "OAK_SAPLING"
|
||||
repository: "BentoBoxWorld/BSkyBlock"
|
||||
|
@ -304,31 +304,7 @@ world:
|
||||
# These settings/flags are hidden from users
|
||||
# Ops can toggle hiding in-game using SHIFT-LEFT-CLICK on flags in settings
|
||||
# Added since 1.4.1.
|
||||
hidden-flags:
|
||||
- CHEST_DAMAGE
|
||||
- HURT_MONSTERS
|
||||
- BREAK_SPAWNERS
|
||||
- DISPENSER
|
||||
- DRAGON_EGG
|
||||
- DROPPER
|
||||
- EXPERIENCE_BOTTLE_THROWING
|
||||
- HURT_VILLAGERS
|
||||
- MOUNT_INVENTORY
|
||||
- NOTE_BLOCK
|
||||
- TURTLE_EGGS
|
||||
- PVP_END
|
||||
- FIRE_BURNING
|
||||
- FIRE_IGNITE
|
||||
- FIRE_SPREAD
|
||||
- PVP_NETHER
|
||||
- PVP_OVERWORLD
|
||||
- TNT_DAMAGE
|
||||
- MONSTER_NATURAL_SPAWN
|
||||
- MONSTER_SPAWNERS_SPAWN
|
||||
- ANIMAL_SPAWNERS_SPAWN
|
||||
- ANIMAL_NATURAL_SPAWN
|
||||
- LEAF_DECAY
|
||||
- BREAK_HOPPERS
|
||||
hidden-flags: []
|
||||
# Visitor banned commands - Visitors to islands cannot use these commands in this world
|
||||
visitor-banned-commands:
|
||||
- spawner
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: BentoBox-BSkyBlock
|
||||
main: world.bentobox.bskyblock.BSkyBlockPladdon
|
||||
version: ${project.version}${build.number}
|
||||
api-version: "1.19"
|
||||
api-version: "1.21"
|
||||
|
||||
authors: [tastybento]
|
||||
contributors: ["The BentoBoxWorld Community"]
|
||||
|
@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
@ -59,6 +60,7 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bskyblock.generators.ChunkGeneratorWorld;
|
||||
import world.bentobox.bskyblock.mocks.ServerMocks;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -101,6 +103,7 @@ public class BSkyBlockTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
deleteAll(new File("database"));
|
||||
@ -123,6 +126,7 @@ public class BSkyBlockTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
@ -160,6 +164,9 @@ public class BSkyBlockTest {
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
|
||||
@SuppressWarnings("deprecation")
|
||||
UnsafeValues unsafe = mock(UnsafeValues.class);
|
||||
when(Bukkit.getUnsafe()).thenReturn(unsafe);
|
||||
|
||||
// Addon
|
||||
addon = new BSkyBlock();
|
||||
|
@ -13,9 +13,12 @@ import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import world.bentobox.bskyblock.mocks.ServerMocks;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -29,9 +32,15 @@ public class SettingsTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
s = new Settings();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.Settings#setFriendlyName(java.lang.String)}.
|
||||
*/
|
||||
|
@ -17,6 +17,7 @@ import java.util.Random;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
@ -30,6 +31,7 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.bskyblock.mocks.ServerMocks;
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
import world.bentobox.bskyblock.Settings;
|
||||
|
||||
@ -49,7 +51,6 @@ public class ChunkGeneratorWorldTest {
|
||||
private final Random random = new Random();
|
||||
@Mock
|
||||
private BiomeGrid biomeGrid;
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private ChunkData data;
|
||||
@ -59,11 +60,16 @@ public class ChunkGeneratorWorldTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
// Bukkit
|
||||
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
Server server = mock(Server.class);
|
||||
when(server.createChunkData(any())).thenReturn(data);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
@SuppressWarnings("deprecation")
|
||||
UnsafeValues unsafe = mock(UnsafeValues.class);
|
||||
when(Bukkit.getUnsafe()).thenReturn(unsafe);
|
||||
|
||||
// Instance
|
||||
cg = new ChunkGeneratorWorld(addon);
|
||||
@ -71,12 +77,8 @@ public class ChunkGeneratorWorldTest {
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
when(world.getMaxHeight()).thenReturn(16);
|
||||
// Settings
|
||||
settings = new Settings();
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
when(settings.getSeaHeight()).thenReturn(0);
|
||||
when(settings.isNetherRoof()).thenReturn(true);
|
||||
when(settings.getDefaultBiome()).thenReturn(Biome.TAIGA);
|
||||
when(settings.getDefaultNetherBiome()).thenReturn(Biome.CRIMSON_FOREST);
|
||||
when(settings.getDefaultEndBiome()).thenReturn(Biome.END_MIDLANDS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,6 +86,7 @@ public class ChunkGeneratorWorldTest {
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,11 +97,7 @@ public class ChunkGeneratorWorldTest {
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
verify(settings).getDefaultBiome();
|
||||
verify(biomeGrid, times(64)).setBiome(anyInt(), anyInt(), anyInt(), any());
|
||||
// Sea height
|
||||
verify(settings).getSeaHeight();
|
||||
// Void
|
||||
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
|
||||
}
|
||||
@ -109,15 +108,11 @@ public class ChunkGeneratorWorldTest {
|
||||
@Test
|
||||
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldSea() {
|
||||
// Set sea height
|
||||
when(settings.getSeaHeight()).thenReturn(10);
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
|
||||
settings.setSeaHeight(10);
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0, 0, biomeGrid);
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
verify(settings).getDefaultBiome();
|
||||
verify(biomeGrid, times(64)).setBiome(anyInt(), anyInt(), anyInt(), eq(Biome.TAIGA));
|
||||
// Sea height
|
||||
verify(settings, times(2)).getSeaHeight();
|
||||
// Water. Blocks = 16 x 16 x 11 because block 0
|
||||
verify(cd).setRegion(0, 0, 0, 16, 11, 16, Material.WATER);
|
||||
}
|
||||
@ -131,12 +126,8 @@ public class ChunkGeneratorWorldTest {
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
verify(settings).getDefaultEndBiome();
|
||||
// Set biome in end
|
||||
verify(biomeGrid, times(64)).setBiome(anyInt(), anyInt(), anyInt(), eq(Biome.END_MIDLANDS));
|
||||
// Sea height
|
||||
verify(settings, never()).getSeaHeight();
|
||||
// Void
|
||||
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
|
||||
}
|
||||
@ -150,8 +141,6 @@ public class ChunkGeneratorWorldTest {
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Nether roof check
|
||||
verify(settings).isNetherRoof();
|
||||
// Set biome in nether
|
||||
verify(biomeGrid, times(64)).setBiome(anyInt(), anyInt(), anyInt(), eq(Biome.CRIMSON_FOREST));
|
||||
// Nether roof - at least bedrock layer
|
||||
@ -163,14 +152,11 @@ public class ChunkGeneratorWorldTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherNoRoof() {
|
||||
when(settings.isNetherRoof()).thenReturn(false);
|
||||
settings.setNetherRoof(false);
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
verify(settings).getDefaultNetherBiome();
|
||||
// Nether roof check
|
||||
verify(settings).isNetherRoof();
|
||||
// Set biome in nether
|
||||
verify(biomeGrid, times(64)).setBiome(anyInt(), anyInt(), anyInt(), eq(Biome.CRIMSON_FOREST));
|
||||
// Nether roof - at least bedrock layer
|
||||
|
118
src/test/java/world/bentobox/bskyblock/mocks/ServerMocks.java
Normal file
118
src/test/java/world/bentobox/bskyblock/mocks/ServerMocks.java
Normal file
@ -0,0 +1,118 @@
|
||||
package world.bentobox.bskyblock.mocks;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.notNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
public final class ServerMocks {
|
||||
|
||||
public static @NonNull Server newServer() {
|
||||
Server mock = mock(Server.class);
|
||||
|
||||
Logger noOp = mock(Logger.class);
|
||||
when(mock.getLogger()).thenReturn(noOp);
|
||||
when(mock.isPrimaryThread()).thenReturn(true);
|
||||
|
||||
// Unsafe
|
||||
UnsafeValues unsafe = mock(UnsafeValues.class);
|
||||
when(mock.getUnsafe()).thenReturn(unsafe);
|
||||
|
||||
// Server must be available before tags can be mocked.
|
||||
Bukkit.setServer(mock);
|
||||
|
||||
// Bukkit has a lot of static constants referencing registry values. To initialize those, the
|
||||
// registries must be able to be fetched before the classes are touched.
|
||||
Map<Class<? extends Keyed>, Object> registers = new HashMap<>();
|
||||
|
||||
doAnswer(invocationGetRegistry -> registers.computeIfAbsent(invocationGetRegistry.getArgument(0), clazz -> {
|
||||
Registry<?> registry = mock(Registry.class);
|
||||
Map<NamespacedKey, Keyed> cache = new HashMap<>();
|
||||
doAnswer(invocationGetEntry -> {
|
||||
NamespacedKey key = invocationGetEntry.getArgument(0);
|
||||
// Some classes (like BlockType and ItemType) have extra generics that will be
|
||||
// erased during runtime calls. To ensure accurate typing, grab the constant's field.
|
||||
// This approach also allows us to return null for unsupported keys.
|
||||
Class<? extends Keyed> constantClazz;
|
||||
try {
|
||||
//noinspection unchecked
|
||||
constantClazz = (Class<? extends Keyed>) clazz
|
||||
.getField(key.getKey().toUpperCase(Locale.ROOT).replace('.', '_')).getType();
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cache.computeIfAbsent(key, key1 -> {
|
||||
Keyed keyed = mock(constantClazz);
|
||||
doReturn(key).when(keyed).getKey();
|
||||
return keyed;
|
||||
});
|
||||
}).when(registry).get(notNull());
|
||||
return registry;
|
||||
})).when(mock).getRegistry(notNull());
|
||||
|
||||
// Tags are dependent on registries, but use a different method.
|
||||
// This will set up blank tags for each constant; all that needs to be done to render them
|
||||
// functional is to re-mock Tag#getValues.
|
||||
doAnswer(invocationGetTag -> {
|
||||
Tag<?> tag = mock(Tag.class);
|
||||
doReturn(invocationGetTag.getArgument(1)).when(tag).getKey();
|
||||
doReturn(Set.of()).when(tag).getValues();
|
||||
doAnswer(invocationIsTagged -> {
|
||||
Keyed keyed = invocationIsTagged.getArgument(0);
|
||||
Class<?> type = invocationGetTag.getArgument(2);
|
||||
if (!type.isAssignableFrom(keyed.getClass())) {
|
||||
return null;
|
||||
}
|
||||
// Since these are mocks, the exact instance might not be equal. Consider equal keys equal.
|
||||
return tag.getValues().contains(keyed)
|
||||
|| tag.getValues().stream().anyMatch(value -> value.getKey().equals(keyed.getKey()));
|
||||
}).when(tag).isTagged(notNull());
|
||||
return tag;
|
||||
}).when(mock).getTag(notNull(), notNull(), notNull());
|
||||
|
||||
// Once the server is all set up, touch BlockType and ItemType to initialize.
|
||||
// This prevents issues when trying to access dependent methods from a Material constant.
|
||||
try {
|
||||
Class.forName("org.bukkit.inventory.ItemType");
|
||||
Class.forName("org.bukkit.block.BlockType");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
public static void unsetBukkitServer() {
|
||||
try {
|
||||
Field server = Bukkit.class.getDeclaredField("server");
|
||||
server.setAccessible(true);
|
||||
server.set(null, null);
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ServerMocks() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user