How to use WorldBorderMock method of be.seeseemelk.mockbukkit.WorldBorderMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.WorldBorderMock.WorldBorderMock

Source:WorldMock.java Github

copy

Full Screen

...193 private final Biome defaultBiome;194 private final int grassHeight;195 private final int minHeight;196 private final int maxHeight;197 private WorldBorderMock worldBorder;198 private final UUID uuid = UUID.randomUUID();199 private Environment environment = Environment.NORMAL;200 private String name = "World";201 private Location spawnLocation;202 private long fullTime = 0;203 private int weatherDuration;204 private boolean thundering;205 private int thunderDuration;206 private boolean storming;207 private int clearWeatherDuration;208 private long seed = 0;209 private @NotNull WorldType worldType = WorldType.NORMAL;210 private final BiomeProviderMock biomeProviderMock = new BiomeProviderMock();211 private final @NotNull Map<Coordinate, Biome> biomes = new HashMap<>();212 private @NotNull Difficulty difficulty = Difficulty.NORMAL;213 private boolean allowAnimals = true;214 private boolean allowMonsters = true;215 /**216 * Creates a new mock world.217 *218 * @param defaultBlock The block that is spawned at locations 1 to {@code grassHeight}219 * @param minHeight The minimum height of the world.220 * @param maxHeight The maximum height of the world.221 * @param grassHeight The last {@code y} at which {@code defaultBlock} will spawn.222 */223 public WorldMock(Material defaultBlock, int minHeight, int maxHeight, int grassHeight)224 {225 this(defaultBlock, Biome.PLAINS, minHeight, maxHeight, grassHeight);226 }227 /**228 * Creates a new mock world.229 *230 * @param defaultBlock The block that is spawned at locations 1 to {@code grassHeight}231 * @param defaultBiome The biome that every block will be in by default.232 * @param minHeight The minimum height of the world.233 * @param maxHeight The maximum height of the world.234 * @param grassHeight The last {@code y} at which {@code defaultBlock} will spawn.235 */236 public WorldMock(Material defaultBlock, Biome defaultBiome, int minHeight, int maxHeight, int grassHeight)237 {238 this.defaultBlock = defaultBlock;239 this.defaultBiome = defaultBiome;240 this.minHeight = minHeight;241 this.maxHeight = maxHeight;242 this.grassHeight = grassHeight;243 this.server = MockBukkit.getMock();244 // Set the default gamerule values.245 gameRules.put(GameRule.ANNOUNCE_ADVANCEMENTS, true);246 gameRules.put(GameRule.COMMAND_BLOCK_OUTPUT, true);247 gameRules.put(GameRule.DISABLE_ELYTRA_MOVEMENT_CHECK, false);248 gameRules.put(GameRule.DO_DAYLIGHT_CYCLE, true);249 gameRules.put(GameRule.DO_ENTITY_DROPS, true);250 gameRules.put(GameRule.DO_FIRE_TICK, true);251 gameRules.put(GameRule.DO_LIMITED_CRAFTING, false);252 gameRules.put(GameRule.DO_MOB_LOOT, true);253 gameRules.put(GameRule.DO_MOB_SPAWNING, true);254 gameRules.put(GameRule.DO_TILE_DROPS, true);255 gameRules.put(GameRule.DO_WEATHER_CYCLE, true);256 gameRules.put(GameRule.KEEP_INVENTORY, false);257 gameRules.put(GameRule.LOG_ADMIN_COMMANDS, true);258 gameRules.put(GameRule.MAX_COMMAND_CHAIN_LENGTH, 65536);259 gameRules.put(GameRule.MAX_ENTITY_CRAMMING, 24);260 gameRules.put(GameRule.MOB_GRIEFING, true);261 gameRules.put(GameRule.NATURAL_REGENERATION, true);262 gameRules.put(GameRule.RANDOM_TICK_SPEED, 3);263 gameRules.put(GameRule.REDUCED_DEBUG_INFO, false);264 gameRules.put(GameRule.SEND_COMMAND_FEEDBACK, true);265 gameRules.put(GameRule.SHOW_DEATH_MESSAGES, true);266 gameRules.put(GameRule.SPAWN_RADIUS, 10);267 gameRules.put(GameRule.SPECTATORS_GENERATE_CHUNKS, true);268 }269 public WorldMock(@NotNull WorldCreator creator)270 {271 this();272 this.name = creator.name();273 this.worldType = creator.type();274 this.seed = creator.seed();275 this.environment = creator.environment();276 }277 /**278 * Creates a new mock world with a specific height from 0.279 *280 * @param defaultBlock The block that is spawned at locations 1 to {@code grassHeight}281 * @param defaultBiome The biome that every block will be in by default.282 * @param maxHeight The maximum height of the world.283 * @param grassHeight The last {@code y} at which {@code defaultBlock} will spawn.284 */285 public WorldMock(Material defaultBlock, Biome defaultBiome, int maxHeight, int grassHeight)286 {287 this(defaultBlock, defaultBiome, 0, maxHeight, grassHeight);288 }289 /**290 * Creates a new mock world with a specific height from 0.291 *292 * @param defaultBlock The block that is spawned at locations 1 to {@code grassHeight}293 * @param maxHeight The maximum height of the world.294 * @param grassHeight The last {@code y} at which {@code defaultBlock} will spawn.295 */296 public WorldMock(Material defaultBlock, int maxHeight, int grassHeight)297 {298 this(defaultBlock, 0, maxHeight, grassHeight);299 }300 /**301 * Creates a new mock world with a height of 128.302 *303 * @param defaultBlock The block that is spawned at locations 1 to {@code grassHeight}304 * @param grassHeight The last {@code y} at which {@code defaultBlock} will spawn.305 */306 public WorldMock(Material defaultBlock, int grassHeight)307 {308 this(defaultBlock, 128, grassHeight);309 }310 /**311 * Creates a new mock world with a height of 128 and will spawn grass until a {@code y} of 4.312 */313 public WorldMock()314 {315 this(Material.GRASS, 4);316 }317 /**318 * Makes sure that a certain block exists on the coordinate. Returns that block.319 *320 * @param c Creates a block on the given coordinate.321 * @return A newly created block at that location.322 */323 public @NotNull BlockMock createBlock(@NotNull Coordinate c)324 {325 if (c.y >= maxHeight)326 {327 throw new ArrayIndexOutOfBoundsException("Y larger than max height");328 }329 else if (c.y < minHeight)330 {331 throw new ArrayIndexOutOfBoundsException("Y smaller than min height");332 }333 Location location = new Location(this, c.x, c.y, c.z);334 BlockMock block;335 if (c.y == minHeight)336 {337 block = new BlockMock(Material.BEDROCK, location);338 }339 else if (c.y <= grassHeight)340 {341 block = new BlockMock(defaultBlock, location);342 }343 else344 {345 block = new BlockMock(location);346 }347 blocks.put(c, block);348 return block;349 }350 @Override351 public int getEntityCount()352 {353 // TODO Auto-generated method stub354 throw new UnimplementedOperationException();355 }356 @Override357 public int getTileEntityCount()358 {359 // TODO Auto-generated method stub360 throw new UnimplementedOperationException();361 }362 @Override363 public int getTickableTileEntityCount()364 {365 // TODO Auto-generated method stub366 throw new UnimplementedOperationException();367 }368 @Override369 public int getChunkCount()370 {371 // TODO Auto-generated method stub372 throw new UnimplementedOperationException();373 }374 @Override375 public int getPlayerCount()376 {377 // TODO Auto-generated method stub378 throw new UnimplementedOperationException();379 }380 @Override381 public @NotNull MoonPhase getMoonPhase()382 {383 // TODO Auto-generated method stub384 throw new UnimplementedOperationException();385 }386 @Override387 public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to)388 {389 // TODO Auto-generated method stub390 throw new UnimplementedOperationException();391 }392 @Override393 public boolean hasCollisionsIn(@NotNull BoundingBox boundingBox)394 {395 // TODO Auto-generated method stub396 throw new UnimplementedOperationException();397 }398 @Override399 public @NotNull BlockMock getBlockAt(int x, int y, int z)400 {401 return getBlockAt(new Coordinate(x, y, z));402 }403 public @NotNull BlockMock getBlockAt(@NotNull Coordinate coordinate)404 {405 if (blocks.containsKey(coordinate))406 {407 return blocks.get(coordinate);408 }409 else410 {411 return createBlock(coordinate);412 }413 }414 @Override415 public @NotNull BlockMock getBlockAt(@NotNull Location location)416 {417 return getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());418 }419 @Override420 @Deprecated421 public @NotNull Block getBlockAtKey(long key)422 {423 // TODO Auto-generated method stub424 throw new UnimplementedOperationException();425 }426 @Override427 public @NotNull Location getLocationAtKey(long key)428 {429 return World.super.getLocationAtKey(key);430 }431 @Override432 public @NotNull String getName()433 {434 return name;435 }436 /**437 * Give a new name to this world.438 *439 * @param name The new name of this world.440 */441 public void setName(String name)442 {443 this.name = name;444 }445 @Override446 public @NotNull UUID getUID()447 {448 return uuid;449 }450 @Override451 public @NotNull Location getSpawnLocation()452 {453 if (spawnLocation == null)454 {455 setSpawnLocation(0, grassHeight + 1, 0);456 }457 return spawnLocation;458 }459 @Override460 public boolean setSpawnLocation(@NotNull Location location)461 {462 return setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());463 }464 @Override465 public boolean setSpawnLocation(int x, int y, int z)466 {467 if (spawnLocation == null)468 {469 spawnLocation = new Location(this, x, y, z);470 }471 else472 {473 spawnLocation.setX(x);474 spawnLocation.setY(y);475 spawnLocation.setZ(z);476 }477 return true;478 }479 @Override480 public @NotNull List<Entity> getEntities()481 {482 return server.getEntities().stream()483 .filter(entity -> entity.getWorld() == this)484 .filter(EntityMock::isValid)485 .collect(Collectors.toList());486 }487 @Override488 public @NotNull ChunkMock getChunkAt(int x, int z)489 {490 return getChunkAt(new ChunkCoordinate(x, z));491 }492 /**493 * Gets the chunk at a specific chunk coordinate.494 * <p>495 * If there is no chunk recorded at the location, one will be created.496 *497 * @param coordinate The coordinate at which to get the chunk.498 * @return The chunk at the location.499 */500 @NotNull501 public ChunkMock getChunkAt(@NotNull ChunkCoordinate coordinate)502 {503 ChunkMock chunk = loadedChunks.get(coordinate);504 if (chunk == null)505 {506 chunk = new ChunkMock(this, coordinate.getX(), coordinate.getZ());507 loadedChunks.put(coordinate, chunk);508 }509 return chunk;510 }511 @Override512 public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte[] message)513 {514 StandardMessenger.validatePluginMessage(this.server.getMessenger(), source, channel, message);515 for (Player player : this.getPlayers())516 {517 player.sendPluginMessage(source, channel, message);518 }519 }520 @Override521 public @NotNull Set<String> getListeningPluginChannels()522 {523 Set<String> result = new HashSet<>();524 for (Player player : this.getPlayers())525 {526 result.addAll(player.getListeningPluginChannels());527 }528 return result;529 }530 @Override531 public void setMetadata(@NotNull String metadataKey, @NotNull MetadataValue newMetadataValue)532 {533 metadataTable.setMetadata(metadataKey, newMetadataValue);534 }535 @Override536 public @NotNull List<MetadataValue> getMetadata(@NotNull String metadataKey)537 {538 return metadataTable.getMetadata(metadataKey);539 }540 @Override541 public boolean hasMetadata(@NotNull String metadataKey)542 {543 return metadataTable.hasMetadata(metadataKey);544 }545 @Override546 public void removeMetadata(@NotNull String metadataKey, @NotNull Plugin owningPlugin)547 {548 metadataTable.removeMetadata(metadataKey, owningPlugin);549 }550 @Override551 public int getHighestBlockYAt(int x, int z)552 {553 // TODO Auto-generated method stub554 throw new UnimplementedOperationException();555 }556 @Override557 public int getHighestBlockYAt(@NotNull Location location)558 {559 // TODO Auto-generated method stub560 throw new UnimplementedOperationException();561 }562 @Override563 public @NotNull Block getHighestBlockAt(int x, int z)564 {565 // TODO Auto-generated method stub566 throw new UnimplementedOperationException();567 }568 @Override569 public @NotNull Block getHighestBlockAt(Location location)570 {571 // TODO Auto-generated method stub572 throw new UnimplementedOperationException();573 }574 @Override575 @Deprecated576 public int getHighestBlockYAt(int x, int z, @NotNull HeightmapType heightmap) throws UnsupportedOperationException577 {578 // TODO Auto-generated method stub579 throw new UnimplementedOperationException();580 }581 @Override582 public @NotNull Chunk getChunkAt(@NotNull Location location)583 {584 return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);585 }586 @Override587 public @NotNull Chunk getChunkAt(@NotNull Block block)588 {589 return getChunkAt(block.getLocation());590 }591 @Override592 public boolean isChunkLoaded(Chunk chunk)593 {594 // TODO Auto-generated method stub595 throw new UnimplementedOperationException();596 }597 @Override598 public Chunk @NotNull [] getLoadedChunks()599 {600 return loadedChunks.values().toArray(new Chunk[0]);601 }602 @Override603 public void loadChunk(@NotNull Chunk chunk)604 {605 loadChunk(chunk.getX(), chunk.getZ());606 }607 @Override608 public boolean isChunkLoaded(int x, int z)609 {610 ChunkCoordinate coordinate = new ChunkCoordinate(x, z);611 return loadedChunks.containsKey(coordinate);612 }613 @Override614 @Deprecated615 public boolean isChunkInUse(int x, int z)616 {617 // TODO Auto-generated method stub618 throw new UnimplementedOperationException();619 }620 @Override621 public void loadChunk(int x, int z)622 {623 loadChunk(x, z, true);624 }625 @Override626 public boolean loadChunk(int x, int z, boolean generate)627 {628 AsyncCatcher.catchOp("chunk load");629 // TODO Auto-generated method stub630 throw new UnimplementedOperationException();631 }632 @Override633 public boolean unloadChunk(@NotNull Chunk chunk)634 {635 return this.unloadChunk(chunk.getX(), chunk.getZ());636 }637 @Override638 public boolean unloadChunk(int x, int z)639 {640 return unloadChunk(x, z, true);641 }642 @Override643 public boolean unloadChunk(int x, int z, boolean save)644 {645 AsyncCatcher.catchOp("chunk unload");646 // TODO Auto-generated method stub647 throw new UnimplementedOperationException();648 }649 @Override650 public boolean unloadChunkRequest(int x, int z)651 {652 AsyncCatcher.catchOp("chunk unload");653 // TODO Auto-generated method stub654 throw new UnimplementedOperationException();655 }656 @Override657 @Deprecated658 public boolean regenerateChunk(int x, int z)659 {660 AsyncCatcher.catchOp("chunk regenerate");661 // TODO Auto-generated method stub662 throw new UnimplementedOperationException();663 }664 @Override665 @Deprecated666 public boolean refreshChunk(int x, int z)667 {668 // TODO Auto-generated method stub669 throw new UnimplementedOperationException();670 }671 @Override672 public @NotNull ItemEntityMock dropItem(@NotNull Location loc, @NotNull ItemStack item, @Nullable Consumer<Item> function)673 {674 Preconditions.checkNotNull(loc, "The provided location must not be null.");675 Preconditions.checkNotNull(item, "Cannot drop items that are null.");676 Preconditions.checkArgument(!item.getType().isAir(), "Cannot drop air.");677 ItemEntityMock entity = new ItemEntityMock(server, UUID.randomUUID(), item);678 entity.setLocation(loc);679 if (function != null)680 {681 function.accept(entity);682 }683 server.registerEntity(entity);684 callSpawnEvent(entity, null);685 return entity;686 }687 @Override688 public @NotNull ItemEntityMock dropItem(@NotNull Location loc, @NotNull ItemStack item)689 {690 return dropItem(loc, item, null);691 }692 @Override693 public @NotNull ItemEntityMock dropItemNaturally(@NotNull Location location, @NotNull ItemStack item, @Nullable Consumer<Item> function)694 {695 Preconditions.checkNotNull(location, "The provided location must not be null.");696 Random random = ThreadLocalRandom.current();697 double xs = random.nextFloat() * 0.5F + 0.25;698 double ys = random.nextFloat() * 0.5F + 0.25;699 double zs = random.nextFloat() * 0.5F + 0.25;700 Location loc = location.clone();701 loc.setX(loc.getX() + xs);702 loc.setY(loc.getY() + ys);703 loc.setZ(loc.getZ() + zs);704 return dropItem(loc, item, function);705 }706 @Override707 public @NotNull ItemEntityMock dropItemNaturally(@NotNull Location loc, @NotNull ItemStack item)708 {709 return dropItemNaturally(loc, item, null);710 }711 @Override712 public @NotNull Arrow spawnArrow(Location location, Vector direction, float speed, float spread)713 {714 // TODO Auto-generated method stub715 throw new UnimplementedOperationException();716 }717 @Override718 public boolean generateTree(Location location, TreeType type)719 {720 // TODO Auto-generated method stub721 throw new UnimplementedOperationException();722 }723 @Override724 @Deprecated725 public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate)726 {727 // TODO Auto-generated method stub728 throw new UnimplementedOperationException();729 }730 @Override731 public boolean generateTree(Location location, Random random, TreeType type, Predicate<BlockState> statePredicate)732 {733 // TODO Auto-generated method stub734 throw new UnimplementedOperationException();735 }736 public <T extends Entity> @NotNull T spawn(@NotNull Location location, @NotNull Class<T> clazz) throws IllegalArgumentException737 {738 return this.spawn(location, clazz, null, CreatureSpawnEvent.SpawnReason.CUSTOM);739 }740 @Override741 public <T extends Entity> @NotNull T spawn(@NotNull Location location, @NotNull Class<T> clazz, Consumer<T> function) throws IllegalArgumentException742 {743 return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM);744 }745 @Override746 public <T extends Entity> @NotNull T spawn(@NotNull Location location, @NotNull Class<T> clazz, boolean randomizeData, Consumer<T> function) throws IllegalArgumentException747 {748 return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData);749 }750 public <T extends Entity> @NotNull T spawn(@NotNull Location location, @NotNull Class<T> clazz, Consumer<T> function, CreatureSpawnEvent.@NotNull SpawnReason reason) throws IllegalArgumentException751 {752 return this.spawn(location, clazz, function, reason, true);753 }754 @SuppressWarnings("unchecked")755 public <T extends Entity> @NotNull T spawn(@Nullable Location location, @Nullable Class<T> clazz, @Nullable Consumer<T> function, CreatureSpawnEvent.@NotNull SpawnReason reason, boolean randomizeData) throws IllegalArgumentException756 {757 if (location == null || clazz == null)758 {759 throw new IllegalArgumentException("Location or entity class cannot be null");760 }761 EntityMock entity = this.mockEntity(location, clazz, randomizeData);762 entity.setLocation(location);763 if (entity instanceof MobMock mob)764 {765 mob.finalizeSpawn();766 }767 // CraftBukkit doesn't check this when spawning, it's done when the entity is ticking so768 // it ends up being spawned for one tick before being removed. We don't have a great way769 // to do that, so we just do it here.770 if (entity instanceof Monster && this.getDifficulty() == Difficulty.PEACEFUL)771 {772 entity.remove();773 }774 if (function != null)775 {776 function.accept((T) entity);777 }778 server.registerEntity(entity);779 callSpawnEvent(entity, reason);780 return (T) entity;781 }782 @Override783 public @NotNull Entity spawnEntity(@NotNull Location loc, @NotNull EntityType type)784 {785 return spawn(loc, type.getEntityClass());786 }787 @NotNull788 @Override789 public Entity spawnEntity(@NotNull Location loc, @NotNull EntityType type, boolean randomizeData)790 {791 return this.spawn(loc, type.getEntityClass(), randomizeData, null);792 }793 private <T extends Entity> @NotNull EntityMock mockEntity(@NotNull Location location, @NotNull Class<T> clazz, boolean randomizeData)794 {795 AsyncCatcher.catchOp("entity add");796 if (clazz == ArmorStand.class)797 {798 return new ArmorStandMock(server, UUID.randomUUID());799 }800 else if (clazz == ExperienceOrb.class)801 {802 return new ExperienceOrbMock(server, UUID.randomUUID());803 }804 else if (clazz == Firework.class)805 {806 return new FireworkMock(server, UUID.randomUUID());807 }808 else if (clazz == Hanging.class)809 {810 // LeashHitch has no direction and is always centered811 if (LeashHitch.class.isAssignableFrom(clazz))812 {813 throw new UnimplementedOperationException();814 }815 BlockFace spawnFace = BlockFace.SELF;816 BlockFace[] faces = (ItemFrame.class.isAssignableFrom(clazz))817 ? new BlockFace[]{ BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN }818 : new BlockFace[]{ BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };819 for (BlockFace face : faces)820 {821 Block block = this.getBlockAt(location.add(face.getModX(), face.getModY(), face.getModZ()));822 if (!block.getType().isSolid() && (block.getType() != Material.REPEATER && block.getType() != Material.COMPARATOR))823 continue;824 boolean taken = false;825 // TODO: Check if the entity's bounding box collides with any other hanging entities.826 if (taken)827 continue;828 spawnFace = face;829 break;830 }831 if (spawnFace == BlockFace.SELF)832 {833 spawnFace = BlockFace.SOUTH;834 }835 spawnFace = spawnFace.getOppositeFace();836 // TODO: Spawn entities here.837 throw new UnimplementedOperationException();838 }839 else if (clazz == Item.class)840 {841 throw new IllegalArgumentException("Items must be spawned using World#dropItem(...)");842 }843 else if (clazz == FishHook.class)844 {845 return new FishHookMock(server, UUID.randomUUID());846 }847 else if (clazz == Player.class)848 {849 throw new IllegalArgumentException("Player Entities cannot be spawned, use ServerMock#addPlayer(...)");850 }851 else if (clazz == Zombie.class)852 {853 return new ZombieMock(server, UUID.randomUUID());854 }855 else if (clazz == Enderman.class)856 {857 return new EndermanMock(server, UUID.randomUUID());858 }859 else if (clazz == Horse.class)860 {861 return new HorseMock(server, UUID.randomUUID());862 }863 else if (clazz == Sheep.class)864 {865 return new SheepMock(server, UUID.randomUUID());866 }867 else if (clazz == Allay.class)868 {869 return new AllayMock(server, UUID.randomUUID());870 }871 else if (clazz == Warden.class)872 {873 return new WardenMock(server, UUID.randomUUID());874 }875 else if (clazz == Donkey.class)876 {877 return new DonkeyMock(server, UUID.randomUUID());878 }879 else if (clazz == Llama.class)880 {881 return new LlamaMock(server, UUID.randomUUID());882 }883 else if (clazz == Mule.class)884 {885 return new MuleMock(server, UUID.randomUUID());886 }887 else if (clazz == SkeletonHorse.class)888 {889 return new SkeletonHorseMock(server, UUID.randomUUID());890 }891 else if (clazz == ZombieHorse.class)892 {893 return new ZombieHorseMock(server, UUID.randomUUID());894 }895 else if (clazz == Cow.class)896 {897 return new CowMock(server, UUID.randomUUID());898 }899 else if (clazz == Chicken.class)900 {901 return new ChickenMock(server, UUID.randomUUID());902 }903 else if (clazz == Skeleton.class)904 {905 return new SkeletonMock(server, UUID.randomUUID());906 }907 else if (clazz == Stray.class)908 {909 return new StrayMock(server, UUID.randomUUID());910 }911 else if (clazz == WitherSkeleton.class)912 {913 return new WitherSkeletonMock(server, UUID.randomUUID());914 }915 else if (clazz == Spider.class)916 {917 return new SpiderMock(server, UUID.randomUUID());918 }919 else if (clazz == Blaze.class)920 {921 return new BlazeMock(server, UUID.randomUUID());922 }923 else if (clazz == CaveSpider.class)924 {925 return new CaveSpiderMock(server, UUID.randomUUID());926 }927 else if (clazz == Giant.class)928 {929 return new GiantMock(server, UUID.randomUUID());930 }931 else if (clazz == Axolotl.class)932 {933 return new AxolotlMock(server, UUID.randomUUID());934 }935 else if (clazz == Bat.class)936 {937 return new BatMock(server, UUID.randomUUID());938 }939 else if (clazz == Cat.class)940 {941 return new CatMock(server, UUID.randomUUID());942 }943 else if (clazz == Frog.class)944 {945 return new FrogMock(server, UUID.randomUUID());946 }947 else if (clazz == Fox.class)948 {949 return new FoxMock(server, UUID.randomUUID());950 }951 else if (clazz == Ghast.class)952 {953 return new GhastMock(server, UUID.randomUUID());954 }955 else if (clazz == MushroomCow.class)956 {957 return new MushroomCowMock(server, UUID.randomUUID());958 }959 else if (clazz == Tadpole.class)960 {961 return new TadpoleMock(server, UUID.randomUUID());962 }963 else if (clazz == Cod.class)964 {965 return new CodMock(server, UUID.randomUUID());966 }967 else if (clazz == TropicalFish.class)968 {969 return new TropicalFishMock(server, UUID.randomUUID());970 }971 else if (clazz == Salmon.class)972 {973 return new SalmonMock(server, UUID.randomUUID());974 }975 else if (clazz == PufferFish.class)976 {977 return new PufferFishMock(server, UUID.randomUUID());978 }979 else if (clazz == Bee.class)980 {981 return new BeeMock(server, UUID.randomUUID());982 }983 else if (clazz == Creeper.class)984 {985 return new CreeperMock(server, UUID.randomUUID());986 }987 else if (clazz == Wolf.class)988 {989 return new WolfMock(server, UUID.randomUUID());990 }991 else if (clazz == Goat.class)992 {993 return new GoatMock(server, UUID.randomUUID());994 }995 else if (clazz == Egg.class)996 {997 return new EggMock(server, UUID.randomUUID());998 }999 else if (clazz == Pig.class)1000 {1001 return new PigMock(server, UUID.randomUUID());1002 }1003 throw new UnimplementedOperationException();1004 }1005 private void callSpawnEvent(EntityMock entity, CreatureSpawnEvent.@NotNull SpawnReason reason)1006 {1007 boolean canceled; // Here for future implementation (see below)1008 if (entity instanceof LivingEntity living && !(entity instanceof Player))1009 {1010 boolean isAnimal = entity instanceof Animals || entity instanceof WaterMob || entity instanceof Golem;1011 boolean isMonster = entity instanceof Monster || entity instanceof Ghast || entity instanceof Slime;1012 if (reason != CreatureSpawnEvent.SpawnReason.CUSTOM)1013 {1014 if (isAnimal && !getAllowAnimals() || isMonster && !getAllowMonsters())1015 {1016 entity.remove();1017 return;1018 }1019 }1020 canceled = new CreatureSpawnEvent(living, reason).callEvent();1021 }1022 else if (entity instanceof Item item)1023 {1024 canceled = new ItemSpawnEvent(item).callEvent();1025 }1026 else if (entity instanceof Player)1027 {1028 canceled = true; // Shouldn't ever be called here but just for parody.1029 }1030 else if (entity instanceof Projectile)1031 {1032 canceled = new ProjectileLaunchEvent(entity).callEvent();1033 }1034 else1035 {1036 canceled = new EntitySpawnEvent(entity).callEvent();1037 }1038 /* EntityMock#getPassengers() and #getVehicle() isn't implemented1039 if (canceled || entity.isValid())1040 {1041 Entity vehicle = entity.getVehicle();1042 if (vehicle != null)1043 {1044 vehicle.remove();1045 }1046 for (Entity passenger : entity.getPassengers())1047 {1048 passenger.remove();1049 }1050 entity.remove();1051 }1052 */1053 }1054 @Override1055 public @NotNull LightningStrike strikeLightning(Location loc)1056 {1057 // TODO Auto-generated method stub1058 throw new UnimplementedOperationException();1059 }1060 @Override1061 public @NotNull LightningStrike strikeLightningEffect(Location loc)1062 {1063 // TODO Auto-generated method stub1064 throw new UnimplementedOperationException();1065 }1066 public @Nullable Location findLightningRod(@NotNull Location location)1067 {1068 // TODO Auto-generated method stub1069 throw new UnimplementedOperationException();1070 }1071 @Override1072 public @Nullable Location findLightningTarget(@NotNull Location location)1073 {1074 // TODO Auto-generated method stub1075 throw new UnimplementedOperationException();1076 }1077 @Override1078 public @NotNull List<LivingEntity> getLivingEntities()1079 {1080 return getEntities().stream()1081 .filter(LivingEntity.class::isInstance)1082 .map(LivingEntity.class::cast)1083 .collect(Collectors.toList());1084 }1085 @Override1086 @SafeVarargs1087 public final <T extends Entity> @NotNull Collection<T> getEntitiesByClass(Class<T> @NotNull ... classes)1088 {1089 List<T> entities = new ArrayList<>();1090 for (Class<T> clazz : classes)1091 {1092 entities.addAll(getEntitiesByClass(clazz));1093 }1094 return entities;1095 }1096 @Override1097 public <T extends Entity> @NotNull Collection<T> getEntitiesByClass(@NotNull Class<T> cls)1098 {1099 return getEntities().stream()1100 .filter(entity -> cls.isAssignableFrom(entity.getClass()))1101 .map(cls::cast)1102 .collect(Collectors.toList());1103 }1104 @Override1105 public @NotNull Collection<Entity> getEntitiesByClasses(Class<?> @NotNull ... classes)1106 {1107 List<Entity> entities = new ArrayList<>();1108 for (Class<?> clazz : classes)1109 {1110 entities.addAll(getEntities().stream()1111 .filter(entity -> clazz.isAssignableFrom(entity.getClass()))1112 .toList());1113 }1114 return entities;1115 }1116 @Override1117 public @NotNull CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent)1118 {1119 // TODO Auto-generated method stub1120 throw new UnimplementedOperationException();1121 }1122 @Override1123 public @NotNull List<Player> getPlayers()1124 {1125 return Bukkit.getOnlinePlayers().stream().filter(p -> p.getWorld() == this).collect(Collectors.toList());1126 }1127 @Override1128 public @NotNull Collection<Entity> getNearbyEntities(Location location, double x, double y, double z)1129 {1130 // TODO Auto-generated method stub1131 throw new UnimplementedOperationException();1132 }1133 @Override1134 public @Nullable Entity getEntity(@NotNull UUID uuid)1135 {1136 // TODO Auto-generated method stub1137 throw new UnimplementedOperationException();1138 }1139 @Override1140 public long getTime()1141 {1142 return this.getFullTime() % 24000L;1143 }1144 @Override1145 public void setTime(long time)1146 {1147 long base = this.getFullTime() - this.getFullTime() % 24000L;1148 this.setFullTime(base + time % 24000L);1149 }1150 @Override1151 public long getFullTime()1152 {1153 return this.fullTime;1154 }1155 @Override1156 public void setFullTime(long time)1157 {1158 TimeSkipEvent event = new TimeSkipEvent(this, TimeSkipEvent.SkipReason.CUSTOM, time - this.getFullTime());1159 this.server.getPluginManager().callEvent(event);1160 if (!event.isCancelled())1161 {1162 this.fullTime += event.getSkipAmount();1163 }1164 }1165 @Override1166 public boolean isDayTime()1167 {1168 return false;1169 }1170 @Override1171 public boolean hasStorm()1172 {1173 return this.storming;1174 }1175 @Override1176 public void setStorm(boolean hasStorm)1177 {1178 if (this.storming == hasStorm)1179 {1180 return;1181 }1182 WeatherChangeEvent weather = new WeatherChangeEvent(this, hasStorm, WeatherChangeEvent.Cause.PLUGIN);1183 Bukkit.getServer().getPluginManager().callEvent(weather);1184 if (weather.isCancelled())1185 {1186 return;1187 }1188 this.storming = hasStorm;1189 this.setWeatherDuration(0);1190 this.setClearWeatherDuration(0);1191 }1192 @Override1193 public int getWeatherDuration()1194 {1195 return this.weatherDuration;1196 }1197 @Override1198 public void setWeatherDuration(int duration)1199 {1200 this.weatherDuration = duration;1201 }1202 @Override1203 public boolean isThundering()1204 {1205 return this.thundering;1206 }1207 @Override1208 public void setThundering(boolean thundering)1209 {1210 if (this.thundering == thundering)1211 {1212 return;1213 }1214 ThunderChangeEvent thunder = new ThunderChangeEvent(this, thundering, ThunderChangeEvent.Cause.PLUGIN); // Paper1215 Bukkit.getServer().getPluginManager().callEvent(thunder);1216 if (thunder.isCancelled())1217 {1218 return;1219 }1220 this.thundering = thundering;1221 this.setThunderDuration(0);1222 this.setClearWeatherDuration(0);1223 }1224 @Override1225 public int getThunderDuration()1226 {1227 return this.thunderDuration;1228 }1229 @Override1230 public void setThunderDuration(int duration)1231 {1232 this.thunderDuration = duration;1233 }1234 @Override1235 public boolean isClearWeather()1236 {1237 return !this.hasStorm() && !this.isThundering();1238 }1239 @Override1240 public int getClearWeatherDuration()1241 {1242 return this.clearWeatherDuration;1243 }1244 @Override1245 public void setClearWeatherDuration(int duration)1246 {1247 this.clearWeatherDuration = duration;1248 }1249 @Override1250 public boolean createExplosion(double x, double y, double z, float power)1251 {1252 // TODO Auto-generated method stub1253 throw new UnimplementedOperationException();1254 }1255 @Override1256 public boolean createExplosion(double x, double y, double z, float power, boolean setFire)1257 {1258 // TODO Auto-generated method stub1259 throw new UnimplementedOperationException();1260 }1261 @Override1262 public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks)1263 {1264 // TODO Auto-generated method stub1265 throw new UnimplementedOperationException();1266 }1267 @Override1268 public boolean createExplosion(Location loc, float power)1269 {1270 // TODO Auto-generated method stub1271 throw new UnimplementedOperationException();1272 }1273 @Override1274 public boolean createExplosion(Location loc, float power, boolean setFire)1275 {1276 // TODO Auto-generated method stub1277 throw new UnimplementedOperationException();1278 }1279 @Override1280 public boolean createExplosion(@Nullable Entity source, @NotNull Location loc, float power, boolean setFire, boolean breakBlocks)1281 {1282 return false;1283 }1284 @Override1285 public @NotNull Environment getEnvironment()1286 {1287 return this.environment;1288 }1289 /**1290 * Set a new environment type for this world.1291 *1292 * @param environment The world environnement type.1293 */1294 public void setEnvironment(Environment environment)1295 {1296 this.environment = environment;1297 }1298 @Override1299 public long getSeed()1300 {1301 return this.seed;1302 }1303 @Override1304 public boolean getPVP()1305 {1306 // TODO Auto-generated method stub1307 throw new UnimplementedOperationException();1308 }1309 @Override1310 public void setPVP(boolean pvp)1311 {1312 // TODO Auto-generated method stub1313 throw new UnimplementedOperationException();1314 }1315 @Override1316 public ChunkGenerator getGenerator()1317 {1318 // TODO Auto-generated method stub1319 throw new UnimplementedOperationException();1320 }1321 @Nullable1322 @Override1323 public BiomeProvider getBiomeProvider()1324 {1325 return biomeProviderMock;1326 }1327 @Override1328 public void save()1329 {1330 AsyncCatcher.catchOp("world save");1331 // TODO Auto-generated method stub1332 throw new UnimplementedOperationException();1333 }1334 @Override1335 public @NotNull List<BlockPopulator> getPopulators()1336 {1337 // TODO Auto-generated method stub1338 throw new UnimplementedOperationException();1339 }1340 @SuppressWarnings("deprecation")1341 @Override1342 public @NotNull FallingBlock spawnFallingBlock(Location location, org.bukkit.material.MaterialData data) throws IllegalArgumentException1343 {1344 // TODO Auto-generated method stub1345 throw new UnimplementedOperationException();1346 }1347 @Override1348 @Deprecated1349 public @NotNull FallingBlock spawnFallingBlock(Location location, Material material, byte data)1350 throws IllegalArgumentException1351 {1352 // TODO Auto-generated method stub1353 throw new UnimplementedOperationException();1354 }1355 @Override1356 public void playEffect(@NotNull Location location, @NotNull Effect effect, int data)1357 {1358 this.playEffect(location, effect, data, 64);1359 }1360 @Override1361 public void playEffect(@NotNull Location location, @NotNull Effect effect, int data, int radius)1362 {1363 Preconditions.checkNotNull(location, "Location cannot be null");1364 Preconditions.checkNotNull(effect, "Effect cannot be null");1365 Preconditions.checkNotNull(location.getWorld(), "World cannot be null");1366 }1367 @Override1368 public <T> void playEffect(@NotNull Location location, @NotNull Effect effect, T data)1369 {1370 this.playEffect(location, effect, data, 64);1371 }1372 @Override1373 public <T> void playEffect(@NotNull Location location, @NotNull Effect effect, @Nullable T data, int radius)1374 {1375 if (data != null)1376 {1377 Preconditions.checkArgument(effect.getData() != null && effect.getData().isAssignableFrom(data.getClass()), "Wrong kind of data for this effect!");1378 }1379 else1380 {1381 // Special case: the axis is optional for ELECTRIC_SPARK1382 Preconditions.checkArgument(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for this effect!");1383 }1384 }1385 @Override1386 public @NotNull ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome, boolean includeBiomeTempRain)1387 {1388 return new ChunkSnapshotMock(x, z, getMinHeight(), getMaxHeight(), getName(), getFullTime(), Map.of(), (includeBiome || includeBiomeTempRain) ? Map.of() : null);1389 }1390 @Override1391 public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals)1392 {1393 this.allowMonsters = allowMonsters;1394 this.allowAnimals = allowAnimals;1395 }1396 @Override1397 public boolean getAllowAnimals()1398 {1399 return this.allowAnimals;1400 }1401 @Override1402 public boolean getAllowMonsters()1403 {1404 return this.allowMonsters;1405 }1406 @Override1407 @Deprecated1408 public @NotNull Biome getBiome(int x, int z)1409 {1410 return this.getBiome(x, 0, z);1411 }1412 @Override1413 @Deprecated1414 public void setBiome(int x, int z, @NotNull Biome bio)1415 {1416 for (int y = this.getMinHeight(); y < this.getMaxHeight(); y++)1417 {1418 this.setBiome(x, y, z, bio);1419 }1420 }1421 @Override1422 @Deprecated1423 public double getTemperature(int x, int z)1424 {1425 // TODO Auto-generated method stub1426 throw new UnimplementedOperationException();1427 }1428 @Override1429 @Deprecated1430 public double getHumidity(int x, int z)1431 {1432 // TODO Auto-generated method stub1433 throw new UnimplementedOperationException();1434 }1435 @Override1436 public int getMinHeight()1437 {1438 return minHeight;1439 }1440 @Override1441 public int getMaxHeight()1442 {1443 return maxHeight;1444 }1445 @Override1446 public @NotNull BiomeProvider vanillaBiomeProvider()1447 {1448 // TODO Auto-generated method stub1449 throw new UnimplementedOperationException();1450 }1451 @Override1452 public int getSeaLevel()1453 {1454 return SEA_LEVEL;1455 }1456 @Override1457 public boolean getKeepSpawnInMemory()1458 {1459 // TODO Auto-generated method stub1460 throw new UnimplementedOperationException();1461 }1462 @Override1463 public void setKeepSpawnInMemory(boolean keepLoaded)1464 {1465 // TODO Auto-generated method stub1466 throw new UnimplementedOperationException();1467 }1468 @Override1469 public boolean isAutoSave()1470 {1471 // TODO Auto-generated method stub1472 throw new UnimplementedOperationException();1473 }1474 @Override1475 public void setAutoSave(boolean value)1476 {1477 // TODO Auto-generated method stub1478 throw new UnimplementedOperationException();1479 }1480 @Override1481 public @NotNull Difficulty getDifficulty()1482 {1483 return this.difficulty;1484 }1485 @Override1486 public void setDifficulty(@NotNull Difficulty difficulty)1487 {1488 this.difficulty = difficulty;1489 }1490 @Override1491 public @NotNull File getWorldFolder()1492 {1493 // TODO Auto-generated method stub1494 throw new UnimplementedOperationException();1495 }1496 @Override1497 @Deprecated1498 public WorldType getWorldType()1499 {1500 return this.worldType;1501 }1502 @Override1503 public boolean canGenerateStructures()1504 {1505 // TODO Auto-generated method stub1506 throw new UnimplementedOperationException();1507 }1508 @Override1509 @Deprecated1510 public long getTicksPerAnimalSpawns()1511 {1512 // TODO Auto-generated method stub1513 throw new UnimplementedOperationException();1514 }1515 @Override1516 @Deprecated1517 public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns)1518 {1519 // TODO Auto-generated method stub1520 throw new UnimplementedOperationException();1521 }1522 @Override1523 @Deprecated1524 public long getTicksPerMonsterSpawns()1525 {1526 // TODO Auto-generated method stub1527 throw new UnimplementedOperationException();1528 }1529 @Override1530 @Deprecated1531 public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns)1532 {1533 // TODO Auto-generated method stub1534 throw new UnimplementedOperationException();1535 }1536 @Override1537 @Deprecated1538 public int getMonsterSpawnLimit()1539 {1540 // TODO Auto-generated method stub1541 throw new UnimplementedOperationException();1542 }1543 @Override1544 @Deprecated1545 public void setMonsterSpawnLimit(int limit)1546 {1547 // TODO Auto-generated method stub1548 throw new UnimplementedOperationException();1549 }1550 @Override1551 @Deprecated1552 public int getAnimalSpawnLimit()1553 {1554 // TODO Auto-generated method stub1555 throw new UnimplementedOperationException();1556 }1557 @Override1558 @Deprecated1559 public void setAnimalSpawnLimit(int limit)1560 {1561 // TODO Auto-generated method stub1562 throw new UnimplementedOperationException();1563 }1564 @Override1565 @Deprecated1566 public int getWaterAnimalSpawnLimit()1567 {1568 // TODO Auto-generated method stub1569 throw new UnimplementedOperationException();1570 }1571 @Override1572 @Deprecated1573 public void setWaterAnimalSpawnLimit(int limit)1574 {1575 // TODO Auto-generated method stub1576 throw new UnimplementedOperationException();1577 }1578 @Override1579 @Deprecated1580 public int getWaterUndergroundCreatureSpawnLimit()1581 {1582 // TODO Auto-generated method stub1583 throw new UnimplementedOperationException();1584 }1585 @Override1586 @Deprecated1587 public void setWaterUndergroundCreatureSpawnLimit(int limit)1588 {1589 // TODO Auto-generated method stub1590 throw new UnimplementedOperationException();1591 }1592 @Override1593 @Deprecated1594 public int getAmbientSpawnLimit()1595 {1596 // TODO Auto-generated method stub1597 throw new UnimplementedOperationException();1598 }1599 @Override1600 @Deprecated1601 public void setAmbientSpawnLimit(int limit)1602 {1603 // TODO Auto-generated method stub1604 throw new UnimplementedOperationException();1605 }1606 @Override1607 public void playSound(@NotNull Location location, @NotNull Sound sound, float volume, float pitch)1608 {1609 this.playSound(location, sound, SoundCategory.MASTER, volume, pitch);1610 }1611 @Override1612 public void playSound(@NotNull Location location, @NotNull String sound, float volume, float pitch)1613 {1614 this.playSound(location, sound, SoundCategory.MASTER, volume, pitch);1615 }1616 @Override1617 public void playSound(@NotNull Location location, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch)1618 {1619 for (Player player : getPlayers())1620 {1621 player.playSound(location, sound, category, volume, pitch);1622 }1623 }1624 @Override1625 public void playSound(@NotNull Location location, @NotNull String sound, @NotNull SoundCategory category, float volume, float pitch)1626 {1627 for (Player player : getPlayers())1628 {1629 player.playSound(location, sound, category, volume, pitch);1630 }1631 }1632 @Override1633 public void playSound(Entity entity, Sound sound, float volume, float pitch)1634 {1635 this.playSound(entity, sound, SoundCategory.MASTER, volume, pitch);1636 }1637 @Override1638 public void playSound(@Nullable Entity entity, @Nullable Sound sound, @Nullable SoundCategory category, float volume, float pitch)1639 {1640 if (entity == null || entity.getWorld() != this || sound == null || category == null)1641 {1642 // Null values are simply ignored - This is inline with CB behaviour1643 return;1644 }1645 for (Player player : getPlayers())1646 {1647 player.playSound(entity, sound, category, volume, pitch);1648 }1649 }1650 @Override1651 public String @NotNull [] getGameRules()1652 {1653 return gameRules.values().stream().map(Object::toString).collect(Collectors.toList()).toArray(new String[0]);1654 }1655 @Override1656 @Deprecated1657 public String getGameRuleValue(@Nullable String rule)1658 {1659 if (rule == null)1660 {1661 return null;1662 }1663 GameRule<?> gameRule = GameRule.getByName(rule);1664 if (gameRule == null)1665 {1666 return null;1667 }1668 return getGameRuleValue(gameRule).toString();1669 }1670 @SuppressWarnings("unchecked")1671 @Override1672 @Deprecated1673 public boolean setGameRuleValue(@Nullable String rule, @NotNull String value)1674 {1675 if (rule == null)1676 {1677 return false;1678 }1679 GameRule<?> gameRule = GameRule.getByName(rule);1680 if (gameRule == null)1681 {1682 return false;1683 }1684 if (gameRule.getType().equals(Boolean.TYPE)1685 && (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")))1686 {1687 return setGameRule((GameRule<Boolean>) gameRule, value.equalsIgnoreCase("true"));1688 }1689 else if (gameRule.getType().equals(Integer.TYPE))1690 {1691 try1692 {1693 int intValue = Integer.parseInt(value);1694 return setGameRule((GameRule<Integer>) gameRule, intValue);1695 }1696 catch (NumberFormatException e)1697 {1698 return false;1699 }1700 }1701 else1702 {1703 return false;1704 }1705 }1706 @Override1707 public boolean isGameRule(@Nullable String rule)1708 {1709 return rule != null && GameRule.getByName(rule) != null;1710 }1711 @Override1712 public @NotNull WorldBorderMock getWorldBorder()1713 {1714 if (this.worldBorder == null)1715 {1716 this.worldBorder = new WorldBorderMock(this);1717 }1718 return this.worldBorder;1719 }1720 @Override1721 public void spawnParticle(Particle particle, Location location, int count)1722 {1723 // TODO Auto-generated method stub1724 throw new UnimplementedOperationException();1725 }1726 @Override1727 public void spawnParticle(Particle particle, double x, double y, double z, int count)1728 {1729 // TODO Auto-generated method stub1730 throw new UnimplementedOperationException();...

Full Screen

Full Screen

Source:WorldBorderMockTest.java Github

copy

Full Screen

...13import static org.junit.jupiter.api.Assertions.assertEquals;14import static org.junit.jupiter.api.Assertions.assertFalse;15import static org.junit.jupiter.api.Assertions.assertThrows;16import static org.junit.jupiter.api.Assertions.assertTrue;17class WorldBorderMockTest18{19 private ServerMock server;20 private World world;21 private WorldBorder worldBorderMock;22 @BeforeEach23 void setUp()24 {25 server = MockBukkit.mock();26 world = new WorldMock();27 worldBorderMock = world.getWorldBorder();28 }29 @AfterEach30 void tearDown()31 {32 MockBukkit.unmock();33 }34 @Test35 void constructor_NullWorld_ThrowsException()36 {37 assertThrows(NullPointerException.class, () -> new WorldBorderMock(null));38 }39 @Test40 void reset()41 {42 worldBorderMock.reset();43 assertEquals(6.0E7, worldBorderMock.getSize());44 assertEquals(0.2, worldBorderMock.getDamageAmount());45 assertEquals(5.0, worldBorderMock.getDamageBuffer());46 assertEquals(5, worldBorderMock.getWarningDistance());47 assertEquals(15, worldBorderMock.getWarningTime());48 assertEquals(new Location(world, 0, 0, 0), worldBorderMock.getCenter());49 }50 @Test51 void setSize()...

Full Screen

Full Screen

Source:WorldBorderMock.java Github

copy

Full Screen

...13import java.util.concurrent.TimeUnit;14/**15 * A mock world border object.16 */17public class WorldBorderMock implements WorldBorder18{19 private static final double DEFAULT_BORDER_SIZE = 6.0E7D;20 private static final double DEFAULT_DAMAGE_AMOUNT = 0.2D;21 private static final double DEFAULT_DAMAGE_BUFFER = 5.0D;22 private static final int DEFAULT_WARNING_DISTANCE = 5;23 private static final int DEFAULT_WARNING_TIME = 15;24 private static final double DEFAULT_CENTER_X = 0;25 private static final double DEFAULT_CENTER_Z = 0;26 private static final double MAX_CENTER_VALUE = 3.0E7D;27 private static final long MAX_MOVEMENT_TIME = 9223372036854775L;28 private static final double MAX_BORDER_SIZE = 6.0E7D;29 private static final double MIN_BORDER_SIZE = 1.0D;30 private final @NotNull World world;31 private double size;32 private double damageAmount;33 private double damageBuffer;34 private int warningDistance;35 private int warningTime;36 private double centerX;37 private double centerZ;38 /**39 * Creates a new world border mock40 *41 * @param world The world it is the border of42 */43 public WorldBorderMock(@NotNull World world)44 {45 Preconditions.checkNotNull(world, "World cannot be null");46 this.world = world;47 reset();48 }49 @Override50 public @Nullable World getWorld()51 {52 return this.world;53 }54 @Override55 public void reset()56 {57 setSize(DEFAULT_BORDER_SIZE);58 setDamageAmount(DEFAULT_DAMAGE_AMOUNT);59 setDamageBuffer(DEFAULT_DAMAGE_BUFFER);60 setWarningDistance(DEFAULT_WARNING_DISTANCE);61 setWarningTime(DEFAULT_WARNING_TIME);62 setCenter(DEFAULT_CENTER_X, DEFAULT_CENTER_Z);63 }64 @Override65 public double getSize()66 {67 return this.size;68 }69 @Override70 public void setSize(double newSize)71 {72 this.setSize(newSize, 0L);73 }74 @Override75 public void setSize(double newSize, long seconds)76 {77 newSize = Math.min(MAX_BORDER_SIZE, Math.max(MIN_BORDER_SIZE, newSize));78 seconds = Math.min(MAX_MOVEMENT_TIME, Math.max(0L, seconds));79 WorldBorderBoundsChangeEvent.Type moveType = seconds <= 0 ? WorldBorderBoundsChangeEvent.Type.INSTANT_MOVE : WorldBorderBoundsChangeEvent.Type.STARTED_MOVE;80 WorldBorderBoundsChangeEvent event = new WorldBorderBoundsChangeEvent(this.world, this, moveType, this.size, newSize, seconds * 1000L);81 if (!event.callEvent())82 return;83 double millis = event.getDuration();84 newSize = event.getNewSize();85 if (millis <= 0)86 {87 this.size = newSize;88 return;89 }90 double distance = newSize - this.size;91 moveBorderOverTime(distance, millis, newSize);92 }93 @Override94 public void setSize(double newSize, @NotNull TimeUnit unit, long time)95 {96 //TODO: Auto-generated method stub97 throw new UnimplementedOperationException();98 }99 private void moveBorderOverTime(double distance, double millis, double newSize)100 {101 double distancePerTick = distance / ((millis / 1000) * 20);102 final double oldSize = this.size;103 WorldBorderMock thisBorder = this; // We can't use 'this' in the anonymous class below, so we need to store it in a variable.104 new BukkitRunnable()105 {106 @Override107 public void run()108 {109 if ((size < newSize && distance > 0.001) || (size > newSize && distance < -0.001))110 {111 size += distancePerTick;112 }113 else114 {115 size = newSize;116 new WorldBorderBoundsChangeFinishEvent(world, thisBorder, oldSize, newSize, millis).callEvent();117 this.cancel();...

Full Screen

Full Screen

WorldBorderMock

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.bukkit.World;3import org.bukkit.plugin.java.JavaPlugin;4import be.seeseemelk.mockbukkit.MockBukkit;5import be.seeseemelk.mockbukkit.ServerMock;6import be.seeseemelk.mockbukkit.WorldBorderMock;7public final class Main extends JavaPlugin {8 public void onEnable() {9 ServerMock server = MockBukkit.mock();10 World world = server.addSimpleWorld("world");11 WorldBorderMock worldBorder = new WorldBorderMock(world);12 worldBorder.setSize(100);13 getLogger().info("size of world border is: " + worldBorder.getSize());14 server.unloadWorld(world, false);15 }16 public void onDisable() {17 }18}

Full Screen

Full Screen

WorldBorderMock

Using AI Code Generation

copy

Full Screen

1package com.github.jonathanxd.iutils.test;2import be.seeseemelk.mockbukkit.MockBukkit;3import be.seeseemelk.mockbukkit.ServerMock;4import be.seeseemelk.mockbukkit.WorldMock;5import be.seeseemelk.mockbukkit.WorldBorderMock;6import be.seeseemelk.mockbukkit.entity.PlayerMock;7import be.seeseemelk.mockbukkit.inventory.InventoryMock;8import be.seeseemelk.mockbukkit.inventory.InventoryViewMock;9import be.seeseemelk.mockbukkit.inventory.ItemStackBuilderMock;10import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;11import be.seeseemelk.mockbukkit.scoreboard.ScoreboardMock;12import org.bukkit.Location;13import org.bukkit.Material;14import org.bukkit.World;15import org.bukkit.block.Block;16import org.bukkit.entity.Player;17import org.bukkit.inventory.Inventory;18import org.bukkit.inventory.InventoryView;19import org.bukkit.inventory.ItemStack;20import org.bukkit.inventory.PlayerInventory;21import org.bukkit.scheduler.BukkitScheduler;22import org.bukkit.scoreboard.Scoreboard;23import org.junit.jupiter.api.AfterEach;24import org.junit.jupiter.api.BeforeEach;25import org.junit.jupiter.api.Test;26import java.util.ArrayList;27import java.util.List;28import java.util.Optional;29import java.util.UUID;30import static org.junit.jupiter.api.Assertions.*;31public class MockBukkitTest {32 private ServerMock server;33 private WorldMock world;34 private WorldBorderMock worldBorderMock;35 private PlayerMock player;36 private InventoryMock inventory;37 private InventoryViewMock inventoryView;38 private ItemStackBuilderMock itemStackBuilder;39 private BukkitSchedulerMock bukkitScheduler;40 private ScoreboardMock scoreboard;41 public void setUp() {42 server = MockBukkit.mock();43 world = MockBukkit.createWorld("world");44 worldBorderMock = world.getWorldBorder();45 player = server.addPlayer();46 inventory = new InventoryMock(Material.DIRT, 2);47 inventoryView = new InventoryViewMock(player, inventory);48 itemStackBuilder = new ItemStackBuilderMock(Material.DIRT);49 bukkitScheduler = server.getScheduler();50 scoreboard = server.getScoreboardManager().getMainScoreboard();51 }52 public void tearDown() {

Full Screen

Full Screen

WorldBorderMock

Using AI Code Generation

copy

Full Screen

1WorldBorderMock border = new WorldBorderMock();2border.setCenter(0, 0);3border.setSize(100);4border.setWarningDistance(20);5border.setWarningTime(10);6border.setDamageAmount(0.5);7border.setDamageBuffer(10);8WorldBorderMock border = new WorldBorderMock();9border.setCenter(0, 0);10border.setSize(100);11border.setWarningDistance(20);12border.setWarningTime(10);13border.setDamageAmount(0.5);14border.setDamageBuffer(10);15WorldBorderMock border = new WorldBorderMock();16border.setCenter(0, 0);17border.setSize(100);18border.setWarningDistance(20);19border.setWarningTime(10);20border.setDamageAmount(0.5);21border.setDamageBuffer(10);22WorldBorderMock border = new WorldBorderMock();23border.setCenter(0, 0);24border.setSize(100);25border.setWarningDistance(20);26border.setWarningTime(10);27border.setDamageAmount(0.5);28border.setDamageBuffer(10);29WorldBorderMock border = new WorldBorderMock();30border.setCenter(0, 0);31border.setSize(100);32border.setWarningDistance(20);33border.setWarningTime(10);34border.setDamageAmount(0.5);35border.setDamageBuffer(10);36WorldBorderMock border = new WorldBorderMock();37border.setCenter(0, 0);38border.setSize(100);39border.setWarningDistance(20);40border.setWarningTime(10);41border.setDamageAmount(0.5);42border.setDamageBuffer(10);

Full Screen

Full Screen

WorldBorderMock

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.bukkit.World;3import org.bukkit.plugin.java.JavaPlugin;4import be.seeseemelk.mockbukkit.WorldBorderMock;5{6 public void onEnable()7 {8 World world = getServer().getWorld("world");9 WorldBorderMock.setSize(world, 100);10 }11}12package com.example;13import org.bukkit.Bukkit;14import org.bukkit.Location;15import org.bukkit.World;16import org.bukkit.plugin.java.JavaPlugin;17import be.seeseemelk.mockbukkit.WorldBorderMock;18{19 public void onEnable()20 {21 World world = getServer().getWorld("world");22 Location location = new Location(world, 0, 0, 0);23 WorldBorderMock.setSize(world, 100, location);24 }25}26package com.example;27import org.bukkit.Bukkit;28import org.bukkit.Location;29import org.bukkit.World;30import org.bukkit.plugin.java.JavaPlugin;31import be.seeseemelk.mockbukkit.WorldBorderMock;32{33 public void onEnable()34 {35 World world = getServer().getWorld("world");36 Location location = new Location(world, 0, 0, 0);37 WorldBorderMock.setSize(world, 100, location, 10);38 }39}

Full Screen

Full Screen

WorldBorderMock

Using AI Code Generation

copy

Full Screen

1public void testBorder()2{3 WorldBorderMock border = new WorldBorderMock();4 border.setRadius(100);5 assertEquals(100, border.getRadius(), 0);6}7public void testBorder()8{9 WorldBorderMock border = new WorldBorderMock();10 border.setRadius(100);11 assertEquals(100, border.getRadius(), 0);12}13public void testBorder()14{15 WorldBorderMock border = new WorldBorderMock();16 border.setRadius(100);17 assertEquals(100, border.getRadius(), 0);18}19public void testBorder()20{21 WorldBorderMock border = new WorldBorderMock();22 border.setRadius(100);23 assertEquals(100, border.getRadius(), 0);24}25public void testBorder()26{27 WorldBorderMock border = new WorldBorderMock();28 border.setRadius(100);29 assertEquals(100, border.getRadius(), 0);30}31public void testBorder()32{33 WorldBorderMock border = new WorldBorderMock();34 border.setRadius(100);35 assertEquals(100, border.getRadius(), 0);36}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful