Best MockBukkit code snippet using be.seeseemelk.mockbukkit.block.BlockMock.tick
Source:WorldMock.java
...869 // TODO Auto-generated method stub870 throw new UnimplementedOperationException();871 }872 @Override873 public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns)874 {875 // TODO Auto-generated method stub876 throw new UnimplementedOperationException();877 }878 @Override879 public long getTicksPerMonsterSpawns()880 {881 // TODO Auto-generated method stub882 throw new UnimplementedOperationException();883 }884 @Override885 public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns)886 {887 // TODO Auto-generated method stub888 throw new UnimplementedOperationException();889 }890 @Override891 public int getMonsterSpawnLimit()892 {893 // TODO Auto-generated method stub894 throw new UnimplementedOperationException();895 }896 @Override897 public void setMonsterSpawnLimit(int limit)898 {899 // TODO Auto-generated method stub900 throw new UnimplementedOperationException();901 }902 @Override903 public int getAnimalSpawnLimit()904 {905 // TODO Auto-generated method stub906 throw new UnimplementedOperationException();907 }908 @Override909 public void setAnimalSpawnLimit(int limit)910 {911 // TODO Auto-generated method stub912 throw new UnimplementedOperationException();913 }914 @Override915 public int getWaterAnimalSpawnLimit()916 {917 // TODO Auto-generated method stub918 throw new UnimplementedOperationException();919 }920 @Override921 public void setWaterAnimalSpawnLimit(int limit)922 {923 // TODO Auto-generated method stub924 throw new UnimplementedOperationException();925 }926 @Override927 public int getAmbientSpawnLimit()928 {929 // TODO Auto-generated method stub930 throw new UnimplementedOperationException();931 }932 @Override933 public void setAmbientSpawnLimit(int limit)934 {935 // TODO Auto-generated method stub936 throw new UnimplementedOperationException();937 }938 @Override939 public void playSound(Location location, Sound sound, float volume, float pitch)940 {941 // TODO Auto-generated method stub942 throw new UnimplementedOperationException();943 }944 @Override945 public void playSound(Location location, String sound, float volume, float pitch)946 {947 // TODO Auto-generated method stub948 throw new UnimplementedOperationException();949 }950 @Override951 public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch)952 {953 // TODO Auto-generated method stub954 throw new UnimplementedOperationException();955 }956 @Override957 public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch)958 {959 // TODO Auto-generated method stub960 throw new UnimplementedOperationException();961 }962 @Override963 public String[] getGameRules()964 {965 return gameRules.values().stream().map(Object::toString).collect(Collectors.toList()).toArray(new String[0]);966 }967 @Override968 public String getGameRuleValue(String rule)969 {970 if (rule == null)971 return null;972 GameRule<?> gameRule = GameRule.getByName(rule);973 if (gameRule == null)974 return null;975 return getGameRuleValue(gameRule).toString();976 }977 @SuppressWarnings("unchecked")978 @Override979 public boolean setGameRuleValue(String rule, String value)980 {981 if (rule == null)982 return false;983 GameRule<?> gameRule = GameRule.getByName(rule);984 if (gameRule == null)985 return false;986 if (gameRule.getType().equals(Boolean.TYPE)987 && (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")))988 return setGameRule((GameRule<Boolean>) gameRule, value.equalsIgnoreCase("true"));989 else if (gameRule.getType().equals(Integer.TYPE))990 {991 try992 {993 int intValue = Integer.parseInt(value);994 return setGameRule((GameRule<Integer>) gameRule, intValue);995 }996 catch (NumberFormatException e)997 {998 return false;999 }1000 }1001 else1002 return false;1003 }1004 @Override1005 public boolean isGameRule(String rule)1006 {1007 return rule != null && GameRule.getByName(rule) != null;1008 }1009 @Override1010 public WorldBorder getWorldBorder()1011 {1012 // TODO Auto-generated method stub1013 throw new UnimplementedOperationException();1014 }1015 @Override1016 public void spawnParticle(Particle particle, Location location, int count)1017 {1018 // TODO Auto-generated method stub1019 throw new UnimplementedOperationException();1020 }1021 @Override1022 public void spawnParticle(Particle particle, double x, double y, double z, int count)1023 {1024 // TODO Auto-generated method stub1025 throw new UnimplementedOperationException();1026 }1027 @Override1028 public <T> void spawnParticle(Particle particle, Location location, int count, T data)1029 {1030 // TODO Auto-generated method stub1031 throw new UnimplementedOperationException();1032 }1033 @Override1034 public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, T data)1035 {1036 // TODO Auto-generated method stub1037 throw new UnimplementedOperationException();1038 }1039 @Override1040 public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,1041 double offsetZ)1042 {1043 // TODO Auto-generated method stub1044 throw new UnimplementedOperationException();1045 }1046 @Override1047 public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,1048 double offsetY, double offsetZ)1049 {1050 // TODO Auto-generated method stub1051 throw new UnimplementedOperationException();1052 }1053 @Override1054 public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,1055 double offsetZ, T data)1056 {1057 // TODO Auto-generated method stub1058 throw new UnimplementedOperationException();1059 }1060 @Override1061 public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,1062 double offsetY, double offsetZ, T data)1063 {1064 // TODO Auto-generated method stub1065 throw new UnimplementedOperationException();1066 }1067 @Override1068 public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,1069 double offsetZ, double extra)1070 {1071 // TODO Auto-generated method stub1072 throw new UnimplementedOperationException();1073 }1074 @Override1075 public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,1076 double offsetY, double offsetZ, double extra)1077 {1078 // TODO Auto-generated method stub1079 throw new UnimplementedOperationException();1080 }1081 @Override1082 public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,1083 double offsetZ, double extra, T data)1084 {1085 // TODO Auto-generated method stub1086 throw new UnimplementedOperationException();1087 }1088 @Override1089 public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,1090 double offsetY, double offsetZ, double extra, T data)1091 {1092 // TODO Auto-generated method stub1093 throw new UnimplementedOperationException();1094 }1095 @Override1096 public FallingBlock spawnFallingBlock(Location location, BlockData data) throws IllegalArgumentException1097 {1098 // TODO Auto-generated method stub1099 throw new UnimplementedOperationException();1100 }1101 @Override1102 public <T> T getGameRuleValue(GameRule<T> rule)1103 {1104 return rule.getType().cast(gameRules.get(rule));1105 }1106 @Override1107 public <T> T getGameRuleDefault(GameRule<T> rule)1108 {1109 // TODO Auto-generated method stub1110 throw new UnimplementedOperationException();1111 }1112 @Override1113 public <T> boolean setGameRule(GameRule<T> rule, T newValue)1114 {1115 gameRules.put(rule, newValue);1116 return true;1117 }1118 @Override1119 public boolean isChunkGenerated(int x, int z)1120 {1121 // TODO Auto-generated method stub1122 throw new UnimplementedOperationException();1123 }1124 @Override1125 public Collection<Entity> getNearbyEntities(Location location, double x, double y, double z,1126 Predicate<Entity> filter)1127 {1128 // TODO Auto-generated method stub1129 throw new UnimplementedOperationException();1130 }1131 @Override1132 public Collection<Entity> getNearbyEntities(BoundingBox boundingBox)1133 {1134 // TODO Auto-generated method stub1135 throw new UnimplementedOperationException();1136 }1137 @Override1138 public Collection<Entity> getNearbyEntities(BoundingBox boundingBox, Predicate<Entity> filter)1139 {1140 // TODO Auto-generated method stub1141 throw new UnimplementedOperationException();1142 }1143 @Override1144 public RayTraceResult rayTraceEntities(Location start, Vector direction, double maxDistance)1145 {1146 // TODO Auto-generated method stub1147 throw new UnimplementedOperationException();1148 }1149 @Override1150 public RayTraceResult rayTraceEntities(Location start, Vector direction, double maxDistance, double raySize)1151 {1152 // TODO Auto-generated method stub1153 throw new UnimplementedOperationException();1154 }1155 @Override1156 public RayTraceResult rayTraceEntities(Location start, Vector direction, double maxDistance,1157 Predicate<Entity> filter)1158 {1159 // TODO Auto-generated method stub1160 throw new UnimplementedOperationException();1161 }1162 @Override1163 public RayTraceResult rayTraceEntities(Location start, Vector direction, double maxDistance, double raySize,1164 Predicate<Entity> filter)1165 {1166 // TODO Auto-generated method stub1167 throw new UnimplementedOperationException();1168 }1169 @Override1170 public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance)1171 {1172 // TODO Auto-generated method stub1173 throw new UnimplementedOperationException();1174 }1175 @Override1176 public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance,1177 FluidCollisionMode fluidCollisionMode)1178 {1179 // TODO Auto-generated method stub1180 throw new UnimplementedOperationException();1181 }1182 @Override1183 public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance,1184 FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks)1185 {1186 // TODO Auto-generated method stub1187 throw new UnimplementedOperationException();1188 }1189 @Override1190 public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance,1191 FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize,1192 Predicate<Entity> filter)1193 {1194 // TODO Auto-generated method stub1195 throw new UnimplementedOperationException();1196 }1197 @Override1198 public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,1199 double offsetZ, double extra, T data, boolean force)1200 {1201 // TODO Auto-generated method stub1202 throw new UnimplementedOperationException();1203 }1204 @Override1205 public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,1206 double offsetY, double offsetZ, double extra, T data, boolean force)1207 {1208 // TODO Auto-generated method stub1209 throw new UnimplementedOperationException();1210 }1211 @Override1212 public Location locateNearestStructure(Location origin, StructureType structureType, int radius,1213 boolean findUnexplored)1214 {1215 // TODO Auto-generated method stub1216 throw new UnimplementedOperationException();1217 }1218 @Override1219 public boolean isChunkForceLoaded(int x, int z)1220 {1221 // TODO Auto-generated method stub1222 throw new UnimplementedOperationException();1223 }1224 @Override1225 public void setChunkForceLoaded(int x, int z, boolean forced)1226 {1227 // TODO Auto-generated method stub1228 throw new UnimplementedOperationException();1229 }1230 @Override1231 public Collection<Chunk> getForceLoadedChunks()1232 {1233 // TODO Auto-generated method stub1234 throw new UnimplementedOperationException();1235 }1236 @Override1237 public boolean addPluginChunkTicket(int x, int z, Plugin plugin)1238 {1239 // TODO Auto-generated method stub1240 throw new UnimplementedOperationException();1241 }1242 @Override1243 public boolean removePluginChunkTicket(int x, int z, Plugin plugin)1244 {1245 // TODO Auto-generated method stub1246 throw new UnimplementedOperationException();1247 }1248 @Override1249 public void removePluginChunkTickets(Plugin plugin)1250 {1251 // TODO Auto-generated method stub1252 throw new UnimplementedOperationException();1253 }1254 @Override1255 public Collection<Plugin> getPluginChunkTickets(int x, int z)1256 {1257 // TODO Auto-generated method stub1258 throw new UnimplementedOperationException();1259 }1260 @Override1261 public Map<Plugin, Collection<Chunk>> getPluginChunkTickets()1262 {1263 // TODO Auto-generated method stub1264 throw new UnimplementedOperationException();1265 }1266 @Override1267 public <T extends AbstractArrow> T spawnArrow(Location location, Vector direction, float speed, float spread,1268 Class<T> clazz)1269 {1270 // TODO Auto-generated method stub1271 throw new UnimplementedOperationException();1272 }1273 @Override1274 public Raid locateNearestRaid(Location location, int radius)1275 {1276 // TODO Auto-generated method stub1277 throw new UnimplementedOperationException();1278 }1279 @Override1280 public List<Raid> getRaids()1281 {1282 // TODO Auto-generated method stub1283 throw new UnimplementedOperationException();1284 }1285 public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks,1286 Entity source)1287 {1288 // TODO Auto-generated method stub1289 throw new UnimplementedOperationException();1290 }1291 public boolean createExplosion(Location loc, float power, boolean setFire, boolean breakBlocks)1292 {1293 // TODO Auto-generated method stub1294 throw new UnimplementedOperationException();1295 }1296 public boolean createExplosion(Location loc, float power, boolean setFire, boolean breakBlocks, Entity source)1297 {1298 // TODO Auto-generated method stub1299 throw new UnimplementedOperationException();1300 }1301 @Override1302 public int getHighestBlockYAt(int x, int z, HeightMap heightMap)1303 {1304 // TODO Auto-generated method stub1305 throw new UnimplementedOperationException();1306 }1307 @Override1308 public int getHighestBlockYAt(Location location, HeightMap heightMap)1309 {1310 // TODO Auto-generated method stub1311 throw new UnimplementedOperationException();1312 }1313 @Override1314 public Block getHighestBlockAt(int x, int z, HeightMap heightMap)1315 {1316 // TODO Auto-generated method stub1317 throw new UnimplementedOperationException();1318 }1319 @Override1320 public Block getHighestBlockAt(Location location, HeightMap heightMap)1321 {1322 // TODO Auto-generated method stub1323 throw new UnimplementedOperationException();1324 }1325 @Override1326 public Biome getBiome(int x, int y, int z)1327 {1328 // TODO Auto-generated method stub1329 throw new UnimplementedOperationException();1330 }1331 @Override1332 public void setBiome(int x, int y, int z, Biome bio)1333 {1334 // TODO Auto-generated method stub1335 throw new UnimplementedOperationException();1336 }1337 @Override1338 public double getTemperature(int x, int y, int z)1339 {1340 // TODO Auto-generated method stub1341 throw new UnimplementedOperationException();1342 }1343 @Override1344 public double getHumidity(int x, int y, int z)1345 {1346 // TODO Auto-generated method stub1347 throw new UnimplementedOperationException();1348 }1349 @Override1350 public boolean isHardcore()1351 {1352 // TODO Auto-generated method stub1353 throw new UnimplementedOperationException();1354 }1355 @Override1356 public void setHardcore(boolean hardcore)1357 {1358 // TODO Auto-generated method stub1359 throw new UnimplementedOperationException();1360 }1361 @Override1362 public long getTicksPerWaterSpawns()1363 {1364 // TODO Auto-generated method stub1365 throw new UnimplementedOperationException();1366 }1367 @Override1368 public void setTicksPerWaterSpawns(int ticksPerWaterSpawns)1369 {1370 // TODO Auto-generated method stub1371 throw new UnimplementedOperationException();1372 }1373 @Override1374 public long getTicksPerAmbientSpawns()1375 {1376 // TODO Auto-generated method stub1377 throw new UnimplementedOperationException();1378 }1379 @Override1380 public void setTicksPerAmbientSpawns(int ticksPerAmbientSpawns)1381 {1382 // TODO Auto-generated method stub1383 throw new UnimplementedOperationException();1384 }1385 @Override1386 public DragonBattle getEnderDragonBattle()1387 {1388 // TODO Auto-generated method stub1389 throw new UnimplementedOperationException();1390 }1391 @Override1392 public boolean setSpawnLocation(int x, int y, int z, float angle)1393 {1394 // TODO Auto-generated method stub1395 throw new UnimplementedOperationException();1396 }1397 @Override1398 public long getTicksPerWaterAmbientSpawns()1399 {1400 // TODO Auto-generated method stub1401 throw new UnimplementedOperationException();1402 }1403 @Override1404 public void setTicksPerWaterAmbientSpawns(int ticksPerAmbientSpawns)1405 {1406 // TODO Auto-generated method stub1407 throw new UnimplementedOperationException();1408 }1409 @Override1410 public int getWaterAmbientSpawnLimit()1411 {1412 // TODO Auto-generated method stub1413 throw new UnimplementedOperationException();1414 }1415 @Override1416 public void setWaterAmbientSpawnLimit(int limit)1417 {1418 // TODO Auto-generated method stub...
Source:FurnaceListenerTest.java
...233 var event = new FurnaceSmeltEvent(block, input, recipe.getResult());234 assertDoesNotThrow(() -> listener.onFurnaceSmelt(event));235 assertThat("Event is never cancelled", !event.isCancelled());236 }237 @DisplayName("Silk touch furnaces pause during tick completion.")238 @Test239 void testPauseSilkFurnaceSmelt() {240 tile.setBurnTime(BURN_TIME);241 itemStack.addUnsafeEnchantment(Enchantment.SILK_TOUCH, 1);242 var enchantableBlock = newBlock();243 assertThat("Block must be valid", enchantableBlock, is(notNullValue()));244 var event = new FurnaceSmeltEvent(block, recipe.getInput(), recipe.getResult());245 assertDoesNotThrow(() -> listener.onFurnaceSmelt(event));246 assertDoesNotThrow(() -> MockBukkit.getMock().getScheduler().performOneTick());247 assertThat("Event is never cancelled", !event.isCancelled());248 }249 @DisplayName("Non-furnace clicks are ignored.")250 @Test251 void onInventoryClick() {...
Source:WorldListenerTest.java
1package com.github.jikoo.enchantableblocks.listener;2import static org.hamcrest.CoreMatchers.is;3import static org.hamcrest.CoreMatchers.notNullValue;4import static org.hamcrest.CoreMatchers.nullValue;5import static org.hamcrest.MatcherAssert.assertThat;6import static org.hamcrest.Matchers.greaterThan;7import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;8import static org.mockito.Mockito.mock;9import static org.mockito.Mockito.when;10import be.seeseemelk.mockbukkit.MockBukkit;11import be.seeseemelk.mockbukkit.ServerMock;12import be.seeseemelk.mockbukkit.WorldMock;13import be.seeseemelk.mockbukkit.block.BlockMock;14import be.seeseemelk.mockbukkit.entity.ItemEntityMock;15import be.seeseemelk.mockbukkit.plugin.PluginManagerMock;16import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;17import com.github.jikoo.enchantableblocks.block.impl.dummy.DummyEnchantableBlock.DummyEnchantableRegistration;18import com.github.jikoo.enchantableblocks.registry.EnchantableBlockManager;19import com.google.common.base.Preconditions;20import java.util.Collection;21import java.util.EnumSet;22import java.util.Set;23import java.util.UUID;24import java.util.stream.Collectors;25import org.bukkit.GameMode;26import org.bukkit.Location;27import org.bukkit.Material;28import org.bukkit.block.Block;29import org.bukkit.block.BlockFace;30import org.bukkit.block.BlockState;31import org.bukkit.enchantments.Enchantment;32import org.bukkit.entity.Entity;33import org.bukkit.entity.Item;34import org.bukkit.entity.Player;35import org.bukkit.event.EventHandler;36import org.bukkit.event.Listener;37import org.bukkit.event.block.BlockBreakEvent;38import org.bukkit.event.block.BlockDropItemEvent;39import org.bukkit.event.block.BlockPlaceEvent;40import org.bukkit.event.world.ChunkLoadEvent;41import org.bukkit.event.world.ChunkUnloadEvent;42import org.bukkit.inventory.EquipmentSlot;43import org.bukkit.inventory.ItemStack;44import org.bukkit.inventory.PlayerInventory;45import org.bukkit.plugin.Plugin;46import org.bukkit.util.BoundingBox;47import org.bukkit.util.Consumer;48import org.jetbrains.annotations.NotNull;49import org.jetbrains.annotations.Nullable;50import org.junit.jupiter.api.AfterAll;51import org.junit.jupiter.api.AfterEach;52import org.junit.jupiter.api.BeforeAll;53import org.junit.jupiter.api.BeforeEach;54import org.junit.jupiter.api.DisplayName;55import org.junit.jupiter.api.Test;56import org.junit.jupiter.api.TestInstance;57@DisplayName("Feature: Listen for world events.")58@TestInstance(TestInstance.Lifecycle.PER_CLASS)59class WorldListenerTest {60 private Plugin plugin;61 private PluginManagerMock pluginManager;62 private WorldMock worldMock;63 private Player player;64 private BukkitSchedulerMock scheduler;65 private EnchantableBlockManager manager;66 private Block block;67 private ItemStack itemStack;68 @BeforeAll69 void setUpAll() {70 ServerMock serverMock = MockBukkit.mock();71 worldMock = new WorldMock() {72 @Override73 public @NotNull Collection<Entity> getNearbyEntities(@NotNull BoundingBox boundingBox) {74 return getEntities().stream().filter(75 entity -> entity.isValid() && boundingBox.contains(entity.getLocation().toVector()))76 .collect(Collectors.toList());77 }78 @Override79 public @NotNull ItemEntityMock dropItem(@NotNull Location loc, @NotNull ItemStack item, @Nullable Consumer<Item> function) {80 Preconditions.checkNotNull(loc, "The provided location must not be null.");81 Preconditions.checkNotNull(item, "Cannot drop items that are null.");82 Preconditions.checkArgument(!item.getType().isAir(), "Cannot drop air.");83 ItemEntityMock entity = new ItemEntityMock(serverMock, UUID.randomUUID(), item);84 entity.setLocation(loc);85 if (function != null) {86 function.accept(entity);87 }88 serverMock.registerEntity(entity);89 return entity;90 }91 };92 worldMock.setName("world");93 serverMock.addWorld(worldMock);94 // Set up a fake block that implements getDrops95 block = new BlockMock(Material.DIRT, new Location(worldMock, 0, 0, 0)) {96 @Override97 public @NotNull BoundingBox getBoundingBox() {98 return BoundingBox.of(this);99 }100 @Override101 public @NotNull Collection<ItemStack> getDrops() {102 return getDrops(null);103 }104 @Override105 public @NotNull Collection<ItemStack> getDrops(@Nullable ItemStack tool) {106 if (tool == null) {107 return Set.of();108 }109 return Set.of(new ItemStack(this.getType()));110 }111 };112 }113 @AfterAll114 void tearDownAll() {115 MockBukkit.unmock();116 }117 @BeforeEach118 void setUp() {119 var server = MockBukkit.getMock();120 PlayerInventory inventory = mock(PlayerInventory.class);121 when(inventory.getItemInMainHand()).thenReturn(new ItemStack(Material.DIAMOND_PICKAXE));122 player = mock(Player.class);123 when(player.getInventory()).thenReturn(inventory);124 scheduler = server.getScheduler();125 plugin = MockBukkit.createMockPlugin("EnchantableBlocks");126 manager = new EnchantableBlockManager(plugin);127 // Register dummy with manager128 var registration = new DummyEnchantableRegistration(129 plugin,130 Set.of(Enchantment.DIG_SPEED),131 EnumSet.of(Material.COAL_ORE, Material.DEEPSLATE_COAL_ORE)132 );133 manager.getRegistry().register(registration);134 pluginManager = server.getPluginManager();135 pluginManager.clearEvents();136 Listener listener = new WorldListener(plugin, manager);137 pluginManager.registerEvents(listener, plugin);138 // Reset block type139 block.setType(Material.DIRT);140 // Create default item141 itemStack = new ItemStack(Material.COAL_ORE);142 }143 @AfterEach144 void tearDown() {145 worldMock.getEntities().forEach(Entity::remove);146 plugin.getServer().getScheduler().cancelTasks(plugin);147 pluginManager.clearPlugins();148 }149 @DisplayName("Chunk loading loads blocks from storage.")150 @Test151 void testChunkLoad() {152 var event = new ChunkLoadEvent(block.getChunk(), false);153 assertDoesNotThrow(() -> pluginManager.callEvent(event));154 assertDoesNotThrow(() -> scheduler.performTicks(2L));155 }156 @DisplayName("Chunk unloads unload blocks from storage.")157 @Test158 void testChunkUnload() {159 var event = new ChunkUnloadEvent(block.getChunk(), false);160 assertDoesNotThrow(() -> pluginManager.callEvent(event));161 }162 @DisplayName("Placing invalid blocks does nothing.")163 @Test164 void testInvalidBlockPlace() {165 BlockState replacedState = block.getState();166 block.setType(itemStack.getType());167 var event = new BlockPlaceEvent(block, replacedState, block.getRelative(BlockFace.NORTH),168 itemStack, player, true, EquipmentSlot.HAND);169 assertDoesNotThrow(() -> pluginManager.callEvent(event));170 assertThat("Block must not be created", manager.getBlock(block), is(nullValue()));171 }172 @DisplayName("Placing valid blocks creates enchanted blocks.")173 @Test174 void testValidBlockPlace() {175 BlockState replacedState = block.getState();176 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);177 block.setType(itemStack.getType());178 var event = new BlockPlaceEvent(block, replacedState, block.getRelative(BlockFace.NORTH),179 itemStack, player, true, EquipmentSlot.HAND);180 assertDoesNotThrow(() -> pluginManager.callEvent(event));181 assertThat("Block must be created", manager.getBlock(block), is(notNullValue()));182 }183 @DisplayName("Breaking invalid blocks does nothing.")184 @Test185 void testInvalidBlockBreak() {186 assertThat("Block must be null", manager.getBlock(block), is(nullValue()));187 var event = new BlockBreakEvent(block, player);188 assertDoesNotThrow(() -> pluginManager.callEvent(event));189 }190 @DisplayName("Breaking bad blocks does nothing.")191 @Test192 void testBadBlockBreak() {193 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);194 var enchantableBlock = manager.createBlock(block, itemStack);195 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));196 enchantableBlock.getItemStack().setType(Material.AIR);197 var event = new BlockBreakEvent(block, player);198 assertDoesNotThrow(() -> pluginManager.callEvent(event));199 pluginManager.assertEventNotFired(BlockDropItemEvent.class, "Block must not be in pending drops");200 }201 @DisplayName("Breaking blocks without drops does not drop items.")202 @Test203 void testNoDropBlockBreak() {204 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);205 var enchantableBlock = manager.createBlock(block, itemStack);206 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));207 var event = new BlockBreakEvent(block, player);208 event.setDropItems(false);209 assertDoesNotThrow(() -> pluginManager.callEvent(event));210 pluginManager.assertEventNotFired(BlockDropItemEvent.class, "Block must not be in pending drops");211 }212 @DisplayName("Breaking blocks in creative does not drop items.")213 @Test214 void testCreativeBlockBreak() {215 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);216 var enchantableBlock = manager.createBlock(block, itemStack);217 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));218 var event = new BlockBreakEvent(block, player);219 player.setGameMode(GameMode.CREATIVE);220 assertDoesNotThrow(() -> pluginManager.callEvent(event));221 pluginManager.assertEventNotFired(BlockDropItemEvent.class, "Block must not be in pending drops");222 }223 @DisplayName("Breaking blocks with invalid tool does not drop items.")224 @Test225 void testInvalidToolBlockBreak() {226 when(player.getInventory().getItemInMainHand()).thenReturn(null);227 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);228 var enchantableBlock = manager.createBlock(block, itemStack);229 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));230 var event = new BlockBreakEvent(block, player);231 player.setGameMode(GameMode.CREATIVE);232 assertDoesNotThrow(() -> pluginManager.callEvent(event));233 pluginManager.assertEventNotFired(BlockDropItemEvent.class, "Block must not be in pending drops");234 }235 @DisplayName("Breaking valid blocks drops items.")236 @Test237 void testValidBlockBreak() {238 block.setType(itemStack.getType());239 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);240 var enchantableBlock = manager.createBlock(block, itemStack);241 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));242 var event = new BlockBreakEvent(block, player);243 assertDoesNotThrow(() -> pluginManager.callEvent(event));244 assertDoesNotThrow(scheduler::performOneTick);245 var nearbyEntities = block.getWorld().getNearbyEntities(block.getBoundingBox());246 assertThat("Item must be added to world", nearbyEntities.size(), is(greaterThan(0)));247 pluginManager.assertEventFired("Event must be fired for item", BlockDropItemEvent.class, ignored -> true);248 }249 @DisplayName("Items removed from BlockDropEvent must not be in world")250 @Test251 void testRemoveBlockDropItem() {252 pluginManager.registerEvents(new Listener() {253 @EventHandler254 public void onBlockDropItem(BlockDropItemEvent event) {255 event.getItems().clear();256 }257 }, plugin);258 block.setType(itemStack.getType());259 itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10);260 var enchantableBlock = manager.createBlock(block, itemStack);261 assertThat("Block must not be null", enchantableBlock, is(notNullValue()));262 var event = new BlockBreakEvent(block, player);263 assertDoesNotThrow(() -> pluginManager.callEvent(event));264 assertDoesNotThrow(scheduler::performOneTick);265 var nearbyEntities = block.getWorld().getNearbyEntities(block.getBoundingBox());266 assertThat("Item must not be added to world", nearbyEntities.size(), is(0));267 pluginManager.assertEventFired("Event must be fired for item", BlockDropItemEvent.class, ignored -> true);268 }269}...
tick
Using AI Code Generation
1package com.example;2import be.seeseemelk.mockbukkit.MockBukkit;3import be.seeseemelk.mockbukkit.ServerMock;4import be.seeseemelk.mockbukkit.block.BlockMock;5import be.seeseemelk.mockbukkit.block.BlockStateMock;6import be.seeseemelk.mockbukkit.block.data.BlockDataMock;7import org.bukkit.Material;8import org.bukkit.block.Block;9import org.bukkit.block.BlockState;10import org.bukkit.block.data.BlockData;11import org.junit.jupiter.api.AfterEach;12import org.junit.jupiter.api.BeforeEach;13import org.junit.jupiter.api.Test;14public class BlockMockTest {15 private ServerMock server;16 public void setUp() {17 server = MockBukkit.mock();18 }19 public void tearDown() {20 MockBukkit.unmock();21 }22 public void testBlockMock() {23 BlockData blockData = new BlockDataMock(Material.GRASS_BLOCK);24 BlockState blockState = new BlockStateMock(blockData);25 Block block = new BlockMock(blockState);26 block.tick(1, 1);27 }28}29plugins {30}31repositories {32 mavenCentral()33}34dependencies {
tick
Using AI Code Generation
1import static org.junit.Assert.assertEquals;2import static org.junit.Assert.assertTrue;3import org.bukkit.Material;4import org.bukkit.block.Block;5import org.bukkit.block.BlockFace;6import org.bukkit.block.data.Ageable;7import org.bukkit.block.data.BlockData;8import org.junit.Test;9import be.seeseemelk.mockbukkit.MockBukkit;10import be.seeseemelk.mockbukkit.ServerMock;11import be.seeseemelk.mockbukkit.block.BlockMock;12public class TestTick {13 public void testTick() {14 ServerMock server = MockBukkit.mock();15 BlockMock block = new BlockMock(Material.WHEAT);16 BlockData blockData = block.getBlockData();17 Ageable ageable = (Ageable) blockData;18 ageable.setAge(5);19 block.setBlockData(blockData);20 block.tick(1);21 blockData = block.getBlockData();22 ageable = (Ageable) blockData;23 assertEquals(6, ageable.getAge());24 server.shutdown();25 }26}27import static org.junit.Assert.assertEquals;28import static org.junit.Assert.assertTrue;29import org.bukkit.Material;30import org.bukkit.block.Block;31import org.bukkit.block.BlockFace;32import org.bukkit.block.data.Ageable;33import org.bukkit.block.data.BlockData;34import org.junit.Test;35import be.seeseemelk.mockbukkit.MockBukkit;36import be.seeseemelk.mockbukkit.ServerMock;37import be.seeseemelk.mockbukkit.block.BlockMock;38public class TestTick {39 public void testTick() {40 ServerMock server = MockBukkit.mock();41 BlockMock block = new BlockMock(Material.WHEAT);42 BlockData blockData = block.getBlockData();43 Ageable ageable = (Ageable) blockData;44 ageable.setAge(5);45 block.setBlockData(blockData);46 block.tick(1);47 blockData = block.getBlockData();48 ageable = (Ageable) blockData;49 assertEquals(6, ageable.getAge());50 server.shutdown();51 }52}
tick
Using AI Code Generation
1import be.seeseemelk.mockbukkit.block.BlockMock;2import org.bukkit.Material;3import org.bukkit.block.Block;4import org.bukkit.block.BlockFace;5import org.bukkit.block.data.Ageable;6import org.bukkit.block.data.BlockData;7import org.bukkit.block.data.type.Crop;8import org.bukkit.block.data.type.Sapling;9import org.bukkit.inventory.ItemStack;10import org.bukkit.material.MaterialData;11import org.junit.Test;12import static org.junit.Assert.*;13import static org.junit.jupiter.api.Assertions.assertEquals;14import static org.junit.jupiter.api.Assertions.assertFalse;15import static org.junit.jupiter.api.Assertions.assertTrue;16import static org.junit.jupiter.api.Assertions.fail;17{18 public void testTick()19 {20 BlockMock block = new BlockMock(Material.WHEAT);21 Crop crop = (Crop) block.getBlockData();22 crop.setAge(7);23 block.setBlockData(crop);24 block.tick(1);25 crop = (Crop) block.getBlockData();26 assertEquals(8, crop.getAge());27 block.tick(1);28 crop = (Crop) block.getBlockData();29 assertEquals(9, crop.getAge());30 block.tick(1);31 crop = (Crop) block.getBlockData();32 assertEquals(9, crop.getAge());33 }34}35package be.seeseemelk.mockbukkit.block;36import java.util.List;37import org.bukkit.*;38import org.bukkit.block.*;39import org.bukkit.block.data.*;40import org.bukkit.block.data.type.*;41import org.bukkit.entity.*;42import org.bukkit.inventory.*;43import org.bukkit.inventory.meta.*;44import org.bukkit.loot.*;45import org.bukkit.material.*;46import org.bukkit.metadata.*;47import org.bukkit.plugin.*;48import org.bukkit.util.*;49import org.jetbrains.annotations.*;50{51 private BlockFace face;52 private Material type;53 private byte data;54 private int lightLevel;55 private BlockData blockData;56 public BlockMock(Material type)57 {58 this(type, (byte) 0);59 }60 public BlockMock(Material type, byte data)61 {62 this.type = type;63 this.data = data;64 this.blockData = Bukkit.createBlockData(type);65 }66 public BlockMock(Material type, BlockFace face)67 {68 this(type, (byte) 0, face);
tick
Using AI Code Generation
1import org.junit.Test;2import org.junit.Before;3import org.junit.After;4import org.junit.Assert;5import org.junit.Rule;6import org.junit.rules.ExpectedException;7import org.junit.rules.Timeout;8import org.junit.runner.RunWith;9import org.junit.runners.JUnit4;10import org.mockito.Mockito;11import org.mockito.invocation.InvocationOnMock;12import org.mockito.stubbing.Answer;13import org.mockito.Mock;14import org.mockito.MockitoAnnotations;15import be.seeseemelk.mockbukkit.MockBukkit;16import be.seeseemelk.mockbukkit.ServerMock;17import be.seeseemelk.mockbukkit.block.BlockMock;18import be.seeseemelk.mockbukkit.block.BlockStateMock;19import be.seeseemelk.mockbukkit.block.data.BlockDataMock;20import be.seeseemelk.mockbukkit.inventory.InventoryMock;21import be.seeseemelk.mockbukkit.inventory.ItemStackMock;22import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;23import org.bukkit.Location;24import org.bukkit.Material;25import org.bukkit.block.Block;26import org.bukkit.block.BlockState;27import org.bukkit.block.data.BlockData;28import org.bukkit.inventory.Inventory;29import org.bukkit.inventory.ItemStack;30import org.bukkit.plugin.PluginManager;31import org.bukkit.scheduler.BukkitScheduler;32import java.util.ArrayList;33import java.util.List;34import static org.junit.Assert.*;35import static org.mockito.Mockito.*;36@RunWith(JUnit4.class)37{38 private ServerMock server;39 private BlockMock block;40 private BlockStateMock blockState;41 private BlockDataMock blockData;42 private InventoryMock inventory;43 private ItemStackMock itemStack;44 private BukkitSchedulerMock scheduler;45 public void setUp() throws Exception46 {47 server = MockBukkit.mock();48 block = new BlockMock(Material.STONE);49 blockState = new BlockStateMock(block);50 blockData = new BlockDataMock();51 inventory = new InventoryMock();52 itemStack = new ItemStackMock(Material.STONE);53 scheduler = new BukkitSchedulerMock();54 }55 public void tearDown() throws Exception56 {57 MockBukkit.unmock();58 }59 public void testBlockTick()60 {61 System.out.println("Testing block tick method");62 block.tick(1);63 assertEquals(1, block.getTicksLived());64 }
tick
Using AI Code Generation
1public void onBlockPlace(BlockPlaceEvent event) {2 event.getBlock().getBlockData().setData((byte) 1);3 event.getBlock().tick(1);4}5public void onBlockPlace(BlockPlaceEvent event) {6 event.getBlock().getBlockData().setData((byte) 1);7 event.getBlock().tick(1);8}9public void onBlockPlace(BlockPlaceEvent event) {10 event.getBlock().getBlockData().setData((byte) 1);11 event.getBlock().tick(1);12}13public void onBlockPlace(BlockPlaceEvent event) {14 event.getBlock().getBlockData().setData((byte) 1);15 event.getBlock().tick(1);16}17public void onBlockPlace(BlockPlaceEvent event) {18 event.getBlock().getBlockData().setData((byte) 1);19 event.getBlock().tick(1);20}21public void onBlockPlace(BlockPlaceEvent event) {22 event.getBlock().getBlockData().setData((byte) 1);23 event.getBlock().tick(1);24}
tick
Using AI Code Generation
1package com.example;2import org.bukkit.Material;3import org.bukkit.block.Block;4import be.seeseemelk.mockbukkit.block.BlockMock;5public class Main {6 public static void main(String[] args) {7 BlockMock block = new BlockMock(Material.STONE);8 block.setLocation(0, 0, 0);9 block.tick(1);10 Block block2 = block.getWorld().getBlockAt(0, 0, 0);11 System.out.println(block2.getType());12 }13}14package com.example;15import org.bukkit.Material;16import org.bukkit.block.Block;17import be.seeseemelk.mockbukkit.block.BlockMock;18public class Main {19 public static void main(String[] args) {20 BlockMock block = new BlockMock(Material.STONE);21 block.setLocation(0, 0, 0);22 block.tick(1);23 Block block2 = block.getWorld().getBlockAt(0, 0, 0);24 System.out.println(block2.getType());25 }26}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!