Best MockBukkit code snippet using be.seeseemelk.mockbukkit.WorldMock.getNearbyEntities
Source:WorldMock.java
...541 {542 return Bukkit.getOnlinePlayers().stream().filter(p -> p.getWorld() == this).collect(Collectors.toList());543 }544 @Override545 public Collection<Entity> getNearbyEntities(Location location, double x, double y, double z)546 {547 // TODO Auto-generated method stub548 throw new UnimplementedOperationException();549 }550 @Override551 public long getTime()552 {553 return this.getFullTime() % 24000L;554 }555 @Override556 public void setTime(long time)557 {558 long base = this.getFullTime() - this.getFullTime() % 24000L;559 this.setFullTime(base + time % 24000L);560 }561 @Override562 public long getFullTime()563 {564 return this.fullTime;565 }566 @Override567 public void setFullTime(long time)568 {569 TimeSkipEvent event = new TimeSkipEvent(this, TimeSkipEvent.SkipReason.CUSTOM, time - this.getFullTime());570 this.server.getPluginManager().callEvent(event);571 if (!event.isCancelled())572 {573 this.fullTime += event.getSkipAmount();574 }575 }576 @Override577 public boolean hasStorm()578 {579 return storming;580 }581 @Override582 public void setStorm(boolean hasStorm)583 {584 storming = hasStorm;585 }586 @Override587 public int getWeatherDuration()588 {589 return weatherDuration;590 }591 @Override592 public void setWeatherDuration(int duration)593 {594 weatherDuration = duration;595 }596 @Override597 public boolean isThundering()598 {599 return thunderDuration > 0;600 }601 @Override602 public void setThundering(boolean thundering)603 {604 thunderDuration = thundering ? 600 : 0;605 }606 @Override607 public int getThunderDuration()608 {609 return thunderDuration;610 }611 @Override612 public void setThunderDuration(int duration)613 {614 thunderDuration = duration;615 }616 @Override617 public boolean createExplosion(double x, double y, double z, float power)618 {619 // TODO Auto-generated method stub620 throw new UnimplementedOperationException();621 }622 @Override623 public boolean createExplosion(double x, double y, double z, float power, boolean setFire)624 {625 // TODO Auto-generated method stub626 throw new UnimplementedOperationException();627 }628 @Override629 public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks)630 {631 // TODO Auto-generated method stub632 throw new UnimplementedOperationException();633 }634 @Override635 public boolean createExplosion(Location loc, float power)636 {637 // TODO Auto-generated method stub638 throw new UnimplementedOperationException();639 }640 @Override641 public boolean createExplosion(Location loc, float power, boolean setFire)642 {643 // TODO Auto-generated method stub644 throw new UnimplementedOperationException();645 }646 @Override647 public Environment getEnvironment()648 {649 return this.environment;650 }651 /**652 * Set a new environment type for this world.653 *654 * @param environment The world environnement type.655 */656 public void setEnvironment(Environment environment)657 {658 this.environment = environment;659 }660 @Override661 public long getSeed()662 {663 // TODO Auto-generated method stub664 throw new UnimplementedOperationException();665 }666 @Override667 public boolean getPVP()668 {669 // TODO Auto-generated method stub670 throw new UnimplementedOperationException();671 }672 @Override673 public void setPVP(boolean pvp)674 {675 // TODO Auto-generated method stub676 throw new UnimplementedOperationException();677 }678 @Override679 public ChunkGenerator getGenerator()680 {681 // TODO Auto-generated method stub682 throw new UnimplementedOperationException();683 }684 @Override685 public void save()686 {687 // TODO Auto-generated method stub688 throw new UnimplementedOperationException();689 }690 @Override691 public List<BlockPopulator> getPopulators()692 {693 // TODO Auto-generated method stub694 throw new UnimplementedOperationException();695 }696 @Override697 public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException698 {699 // TODO Auto-generated method stub700 throw new UnimplementedOperationException();701 }702 @Override703 public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function)704 throws IllegalArgumentException705 {706 // TODO Auto-generated method stub707 throw new UnimplementedOperationException();708 }709 @SuppressWarnings("deprecation")710 @Override711 public FallingBlock spawnFallingBlock(Location location, org.bukkit.material.MaterialData data) throws IllegalArgumentException712 {713 // TODO Auto-generated method stub714 throw new UnimplementedOperationException();715 }716 @Override717 @Deprecated718 public FallingBlock spawnFallingBlock(Location location, Material material, byte data)719 throws IllegalArgumentException720 {721 // TODO Auto-generated method stub722 throw new UnimplementedOperationException();723 }724 @Override725 public void playEffect(Location location, Effect effect, int data)726 {727 // TODO Auto-generated method stub728 throw new UnimplementedOperationException();729 }730 @Override731 public void playEffect(Location location, Effect effect, int data, int radius)732 {733 // TODO Auto-generated method stub734 throw new UnimplementedOperationException();735 }736 @Override737 public <T> void playEffect(Location location, Effect effect, T data)738 {739 // TODO Auto-generated method stub740 throw new UnimplementedOperationException();741 }742 @Override743 public <T> void playEffect(Location location, Effect effect, T data, int radius)744 {745 // TODO Auto-generated method stub746 throw new UnimplementedOperationException();747 }748 @Override749 public ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome, boolean includeBiomeTempRain)750 {751 // TODO Auto-generated method stub752 throw new UnimplementedOperationException();753 }754 @Override755 public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals)756 {757 // TODO Auto-generated method stub758 throw new UnimplementedOperationException();759 }760 @Override761 public boolean getAllowAnimals()762 {763 // TODO Auto-generated method stub764 throw new UnimplementedOperationException();765 }766 @Override767 public boolean getAllowMonsters()768 {769 // TODO Auto-generated method stub770 throw new UnimplementedOperationException();771 }772 @Override773 public Biome getBiome(int x, int z)774 {775 // TODO Auto-generated method stub776 throw new UnimplementedOperationException();777 }778 @Override779 public void setBiome(int x, int z, Biome bio)780 {781 // TODO Auto-generated method stub782 throw new UnimplementedOperationException();783 }784 @Override785 public double getTemperature(int x, int z)786 {787 // TODO Auto-generated method stub788 throw new UnimplementedOperationException();789 }790 @Override791 public double getHumidity(int x, int z)792 {793 // TODO Auto-generated method stub794 throw new UnimplementedOperationException();795 }796 @Override797 public int getMinHeight()798 {799 return MIN_WORLD_HEIGHT;800 }801 @Override802 public int getMaxHeight()803 {804 return MAX_WORLD_HEIGHT;805 }806 @Override807 public int getSeaLevel()808 {809 // TODO Auto-generated method stub810 throw new UnimplementedOperationException();811 }812 @Override813 public boolean getKeepSpawnInMemory()814 {815 // TODO Auto-generated method stub816 throw new UnimplementedOperationException();817 }818 @Override819 public void setKeepSpawnInMemory(boolean keepLoaded)820 {821 // TODO Auto-generated method stub822 throw new UnimplementedOperationException();823 }824 @Override825 public boolean isAutoSave()826 {827 // TODO Auto-generated method stub828 throw new UnimplementedOperationException();829 }830 @Override831 public void setAutoSave(boolean value)832 {833 // TODO Auto-generated method stub834 throw new UnimplementedOperationException();835 }836 @Override837 public void setDifficulty(Difficulty difficulty)838 {839 // TODO Auto-generated method stub840 throw new UnimplementedOperationException();841 }842 @Override843 public Difficulty getDifficulty()844 {845 // TODO Auto-generated method stub846 throw new UnimplementedOperationException();847 }848 @Override849 public File getWorldFolder()850 {851 // TODO Auto-generated method stub852 throw new UnimplementedOperationException();853 }854 @Override855 public WorldType getWorldType()856 {857 // TODO Auto-generated method stub858 throw new UnimplementedOperationException();859 }860 @Override861 public boolean canGenerateStructures()862 {863 // TODO Auto-generated method stub864 throw new UnimplementedOperationException();865 }866 @Override867 public long getTicksPerAnimalSpawns()868 {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 stub...
Source:WorldListenerTest.java
...69 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}...
getNearbyEntities
Using AI Code Generation
1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.WorldMock;4import be.seeseemelk.mockbukkit.entity.PlayerMock;5import org.bukkit.Material;6import org.bukkit.entity.Entity;7import org.bukkit.entity.EntityType;8import org.bukkit.entity.Player;9import org.bukkit.event.entity.EntityDamageEvent;10import org.bukkit.event.entity.EntityDamageEvent.DamageCause;11import org.bukkit.inventory.ItemStack;12import org.junit.After;13import org.junit.Before;14import org.junit.Test;15import java.util.Collection;16import static org.junit.Assert.assertEquals;17import static org.junit.Assert.assertTrue;18{19 private ServerMock server;20 private WorldMock world;21 private PlayerMock player;22 private Entity entity;23 public void setUp()24 {25 server = MockBukkit.mock();26 world = server.addSimpleWorld("world");27 player = server.addPlayer();28 }29 public void tearDown()30 {31 MockBukkit.unmock();32 }33 public void test()34 {35 entity = world.spawnEntity(player.getLocation(), EntityType.DROPPED_ITEM);36 Collection<Entity> nearbyEntities = world.getNearbyEntities(player.getLocation(), 0, 0, 0);37 assertTrue(nearbyEntities.contains(entity));38 }39}40import be.seeseemelk.mockbukkit.MockBukkit;41import be.seeseemelk.mockbukkit.ServerMock;42import be.seeseemelk.mockbukkit.entity.PlayerMock;43import org.bukkit.Material;44import org.bukkit.entity.Entity;45import org.bukkit.entity.EntityType;46import org.bukkit.entity.Player;47import org.bukkit.event.entity.EntityDamageEvent;48import org.bukkit.event.entity.EntityDamageEvent.DamageCause;49import org.bukkit.inventory.ItemStack;50import org.junit.After;51import org.junit.Before;52import org.junit.Test;53import java.util.Collection;54import static org.junit.Assert.assertEquals;55import static org.junit.Assert.assertTrue;56{57 private ServerMock server;58 private PlayerMock player;59 private Entity entity;60 public void setUp()61 {62 server = MockBukkit.mock();63 player = server.addPlayer();64 }65 public void tearDown()
getNearbyEntities
Using AI Code Generation
1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.entity.PlayerMock;4import be.seeseemelk.mockbukkit.entity.EntityMock;5import be.seeseemelk.mockbukkit.WorldMock;6import org.bukkit.Location;7import org.bukkit.entity.Entity;8import org.bukkit.entity.EntityType;9import org.junit.After;10import org.junit.Before;11import org.junit.Test;12import java.util.Collection;13import static org.junit.Assert.assertEquals;14public class TestGetNearbyEntities {15 private ServerMock server;16 private WorldMock world;17 private PlayerMock player;18 public void setUp() {19 server = MockBukkit.mock();20 world = server.addSimpleWorld("world");21 player = server.addPlayer();22 }23 public void tearDown() {24 MockBukkit.unmock();25 }26 public void testGetNearbyEntities() {27 Location loc = new Location(world, 0, 0, 0);28 Entity entity = world.spawnEntity(loc, EntityType.DROPPED_ITEM);29 Collection<Entity> nearbyEntities = world.getNearbyEntities(loc, 10, 10, 10);30 assertEquals(1, nearbyEntities.size());31 assertEquals(entity, nearbyEntities.iterator().next());32 }33}34 at org.junit.Assert.assertEquals(Assert.java:115)35 at org.junit.Assert.assertEquals(Assert.java:144)36 at TestGetNearbyEntities.testGetNearbyEntities(TestGetNearbyEntities.java:39)
getNearbyEntities
Using AI Code Generation
1package com.example;2import org.bukkit.Location;3import org.bukkit.entity.Entity;4import org.bukkit.entity.EntityType;5import org.bukkit.entity.Player;6import org.bukkit.plugin.java.JavaPlugin;7import be.seeseemelk.mockbukkit.MockBukkit;8import be.seeseemelk.mockbukkit.ServerMock;9import be.seeseemelk.mockbukkit.WorldMock;10import be.seeseemelk.mockbukkit.entity.PlayerMock;11public class ExamplePlugin extends JavaPlugin {12 private ServerMock server;13 private WorldMock world;14 private PlayerMock player;15 private Location location;16 private Entity entity;17 public void onEnable() {18 server = MockBukkit.mock();19 world = server.addSimpleWorld("world");20 player = server.addPlayer("Player");21 location = new Location(world, 0, 0, 0);22 entity = world.spawnEntity(location, EntityType.CREEPER);23 Entity[] entities = world.getNearbyEntities(location, 2, 2, 2);24 if (entities.length == 1 && entities[0].equals(entity)) {25 getLogger().info("Test passed!");26 } else {27 getLogger().info("Test failed!");28 }29 MockBukkit.unmock();30 }31}32package com.example;33import org.bukkit.Location;34import org.bukkit.entity.Entity;35import org.bukkit.entity.EntityType;36import org.bukkit.entity.Player;37import org.bukkit.plugin.java.JavaPlugin;38import be.seeseemelk.mockbukkit.MockBukkit;39import be.seeseemelk.mockbukkit.ServerMock;40import be.seeseemelk.mockbukkit.WorldMock;41import be.seeseemelk.mockbukkit.entity.PlayerMock;42public class ExamplePlugin extends JavaPlugin {43 private ServerMock server;44 private WorldMock world;45 private PlayerMock player;46 private Location location;47 private Entity entity;48 public void onEnable() {49 server = MockBukkit.mock();
getNearbyEntities
Using AI Code Generation
1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.WorldMock;4import be.seeseemelk.mockbukkit.entity.PlayerMock;5import org.bukkit.Location;6import org.bukkit.entity.Entity;7import org.bukkit.entity.EntityType;8import org.bukkit.entity.Player;9import org.junit.After;10import org.junit.Before;11import org.junit.Test;12import java.util.Collection;13import static org.junit.Assert.*;14{15 private ServerMock server;16 private WorldMock world;17 private PlayerMock player;18 public void setUp()19 {20 server = MockBukkit.mock();21 world = server.addSimpleWorld("world");22 player = server.addPlayer();23 }24 public void tearDown()25 {26 MockBukkit.unmock();27 }28 public void testGetNearbyEntities()29 {30 Player player = server.addPlayer();31 Entity cow = world.spawnEntity(new Location(world, 0, 0, 0), EntityType.COW);32 Collection<Entity> nearbyEntities = world.getNearbyEntities(player.getLocation(), 10, 10, 10);33 assertTrue(nearbyEntities.contains(cow));34 }35}36import be.seeseemelk.mockbukkit.MockBukkit;37import be.seeseemelk.mockbukkit.ServerMock;38import be.seeseemelk.mockbukkit.WorldMock;39import be.seeseemelk.mockbukkit.entity.PlayerMock;40import org.bukkit.Location;41import org.bukkit.entity.Entity;42import org.bukkit.entity.EntityType;43import org.bukkit.entity.Player;44import org.junit.After;45import org.junit.Before;46import org.junit.Test;47import java.util.Collection;48import static org.junit.Assert.*;49{50 private ServerMock server;51 private WorldMock world;52 private PlayerMock player;
getNearbyEntities
Using AI Code Generation
1package com.example;2import org.bukkit.entity.Entity;3import org.bukkit.entity.Player;4import org.bukkit.plugin.java.JavaPlugin;5import be.seeseemelk.mockbukkit.ServerMock;6import be.seeseemelk.mockbukkit.WorldMock;7{8 public void onEnable()9 {10 ServerMock server = new ServerMock();11 WorldMock world = new WorldMock();12 server.addWorld(world);13 Player player = server.addPlayer();14 for (Entity entity : world.getNearbyEntities(player.getLocation(), 10, 10, 10))15 {16 System.out.println(entity);17 }18 }19}20package com.example;21import org.bukkit.entity.Entity;22import org.bukkit.entity.Player;23import org.bukkit.plugin.java.JavaPlugin;24import be.seeseemelk.mockbukkit.ServerMock;25import be.seeseemelk.mockbukkit.WorldMock;26{27 public void onEnable()28 {29 ServerMock server = new ServerMock();30 WorldMock world = new WorldMock();31 server.addWorld(world);32 Player player = server.addPlayer();33 for (Entity entity : world.getNearbyEntities(player.getLocation(), 10, 10, 10))34 {35 System.out.println(entity);36 }37 }38}39package com.example;40import org.bukkit.entity.Entity;41import org.bukkit.entity.Player;42import org.bukkit.plugin.java.JavaPlugin;43import be.seeseemelk.mockbukkit.ServerMock;44import be.seeseemelk.mockbukkit.WorldMock;45{46 public void onEnable()47 {48 ServerMock server = new ServerMock();49 WorldMock world = new WorldMock();50 server.addWorld(world);51 Player player = server.addPlayer();52 for (Entity entity : world.getNearbyEntities(player.getLocation(), 10, 10, 10))53 {54 System.out.println(entity
getNearbyEntities
Using AI Code Generation
1package be.seeseemelk.mockbukkit;2import org.bukkit.Location;3import org.bukkit.entity.Entity;4import org.bukkit.entity.Player;5import org.bukkit.util.Vector;6import java.util.Collection;7import java.util.List;8import java.util.stream.Collectors;9{10 public WorldMock(org.bukkit.craftbukkit.v1_16_R1.CraftServer server, net.minecraft.server.v1_16_R1.MinecraftServer mcServer, net.minecraft.server.v1_16_R1.WorldServer worldServer, net.minecraft.server.v1_16_R1.WorldData worldData, net.minecraft.server.v1_16_R1.DimensionManager dimensionManager, org.bukkit.craftbukkit.v1_16_R1.generator.InternalChunkGenerator internalChunkGenerator, boolean b)11 {12 super(server, mcServer, worldServer, worldData, dimensionManager, internalChunkGenerator, b);13 }14 public Collection<Entity> getNearbyEntities(Location location, double x, double y, double z)15 {16 Vector min = new Vector(location.getX() - x, location.getY() - y, location.getZ() - z);17 Vector max = new Vector(location.getX() + x, location.getY() + y, location.getZ() + z);18 List<net.minecraft.server.v1_16_R1.Entity> entities = getHandle().getEntities(null, new net.minecraft.server.v1_16_R1.AxisAlignedBB(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()));19 return entities.stream().map(entity -> entity.getBukkitEntity()).collect(Collectors.toList());20 }21}22package be.seeseemelk.mockbukkit;23import org.bukkit.Location;24import org.bukkit.entity.Entity;25import org.bukkit.entity.Player;26import org.bukkit.util.Vector;27import java.util.Collection;28import java.util.List;29import java.util.stream.Collectors;30{31 public WorldMock(org.bukkit.craftbukkit.v1_16_R1.CraftServer server, net.minecraft.server.v1_16_R1.Minecraft
getNearbyEntities
Using AI Code Generation
1import static org.junit.jupiter.api.Assertions.assertEquals;2import java.util.List;3import org.bukkit.entity.Entity;4import org.bukkit.entity.EntityType;5import org.bukkit.entity.Player;6import org.bukkit.entity.Slime;7import org.junit.jupiter.api.AfterEach;8import org.junit.jupiter.api.BeforeEach;9import org.junit.jupiter.api.Test;10import be.seeseemelk.mockbukkit.MockBukkit;11import be.seeseemelk.mockbukkit.ServerMock;12import be.seeseemelk.mockbukkit.WorldMock;13{14 private ServerMock server;15 private WorldMock world;16 private Player player;17 public void setUp()18 {19 server = MockBukkit.mock();20 world = server.addSimpleWorld("world");21 player = server.addPlayer();22 }23 public void tearDown()24 {25 MockBukkit.unmock();26 }27 public void test()28 {29 player.teleport(world.getSpawnLocation());30 Slime slime = (Slime) world.spawnEntity(world.getSpawnLocation(), EntityType.SLIME);31 List<Entity> nearbyEntities = world.getNearbyEntities(player.getLocation(), 10, 10, 10);32 assertEquals(1, nearbyEntities.size());33 assertEquals(slime, nearbyEntities.get(0));34 }35}
getNearbyEntities
Using AI Code Generation
1public class 2 extends JavaPlugin{2 public void onEnable() {3 getServer().getPluginManager().registerEvents(new Listener() {4 public void onPlayerJoin(PlayerJoinEvent event) {5 Player player = event.getPlayer();6 World world = player.getWorld();7 List<Entity> entities = world.getNearbyEntities(player.getLocation(), 10, 10, 10);8 for (Entity entity : entities) {9 player.sendMessage(entity.getType().toString());10 }11 }12 }, this);13 }14}15public class 3 extends JavaPlugin{16 public void onEnable() {17 getServer().getPluginManager().registerEvents(new Listener() {18 public void onPlayerJoin(PlayerJoinEvent event) {19 Player player = event.getPlayer();20 World world = player.getWorld();21 List<Entity> entities = world.getNearbyEntities(player.getLocation(), 10, 10, 10);22 for (Entity entity : entities) {23 player.sendMessage(entity.getType().toString());24 }25 }26 }, this);27 }28}29public class 4 extends JavaPlugin{30 public void onEnable() {31 getServer().getPluginManager().registerEvents(new Listener() {32 public void onPlayerJoin(PlayerJoinEvent event) {33 Player player = event.getPlayer();34 World world = player.getWorld();35 List<Entity> entities = world.getNearbyEntities(player.getLocation(), 10, 10, 10);36 for (Entity entity : entities) {37 player.sendMessage(entity.getType().toString());38 }39 }40 }, this);41 }42}43public class 5 extends JavaPlugin{44 public void onEnable()
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!!