How to use CachedServerIconMock method of be.seeseemelk.mockbukkit.ServerMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.ServerMock.CachedServerIconMock

Source:ServerMock.java Github

copy

Full Screen

...164 private final MockCommandMap commandMap = new MockCommandMap(this);165 private final HelpMapMock helpMap = new HelpMapMock();166 private final StandardMessenger messenger = new StandardMessenger();167 private final Map<Integer, MapViewMock> mapViews = new HashMap<>();168 private CachedServerIconMock serverIcon = new CachedServerIconMock(null);169 private int nextMapId = 1;170 private GameMode defaultGameMode = GameMode.SURVIVAL;171 private ConsoleCommandSenderMock consoleSender;172 private int spawnRadius = 16;173 private @NotNull WarningState warningState = WarningState.DEFAULT;174 private boolean isWhitelistEnabled = false;175 private boolean isWhitelistEnforced = false;176 private final @NotNull Set<OfflinePlayer> whitelistedPlayers = new LinkedHashSet<>();177 public ServerMock()178 {179 ServerMock.registerSerializables();180 // Register default Minecraft Potion Effect Types181 createPotionEffectTypes();182 TagsMock.loadDefaultTags(this, true);183 EnchantmentsMock.registerDefaultEnchantments();184 try185 {186 InputStream stream = ClassLoader.getSystemResourceAsStream("logger.properties");187 LogManager.getLogManager().readConfiguration(stream);188 }189 catch (IOException e)190 {191 logger.warning("Could not load file logger.properties");192 }193 logger.setLevel(Level.ALL);194 try195 {196 buildProperties.load(ClassLoader.getSystemResourceAsStream("build.properties"));197 }198 catch (IOException | NullPointerException e)199 {200 logger.warning("Could not load build properties");201 }202 }203 /**204 * Checks if we are on the main thread. The main thread is the thread used to create this instance of the mock205 * server.206 *207 * @return {@code true} if we are on the main thread, {@code false} if we are running on a different thread.208 */209 public boolean isOnMainThread()210 {211 return mainThread.equals(Thread.currentThread());212 }213 /**214 * Registers an entity so that the server can track it more easily. Should only be used internally.215 *216 * @param entity The entity to register217 */218 public void registerEntity(@NotNull EntityMock entity)219 {220 AsyncCatcher.catchOp("entity add");221 entities.add(entity);222 }223 /**224 * Returns a set of entities that exist on the server instance.225 *226 * @return A set of entities that exist on this server instance.227 */228 @NotNull229 public Set<EntityMock> getEntities()230 {231 return Collections.unmodifiableSet(entities);232 }233 /**234 * Add a specific player to the set.235 *236 * @param player The player to add.237 */238 public void addPlayer(@NotNull PlayerMock player)239 {240 AsyncCatcher.catchOp("player add");241 playerList.addPlayer(player);242 CountDownLatch conditionLatch = new CountDownLatch(1);243 InetSocketAddress address = player.getAddress();244 AsyncPlayerPreLoginEvent preLoginEvent = new AsyncPlayerPreLoginEvent(player.getName(),245 address.getAddress(), player.getUniqueId());246 getPluginManager().callEventAsynchronously(preLoginEvent, (e) -> conditionLatch.countDown());247 try248 {249 conditionLatch.await();250 }251 catch (InterruptedException e)252 {253 getLogger().severe("Interrupted while waiting for AsyncPlayerPreLoginEvent! " +254 (StringUtils.isEmpty(e.getMessage()) ? "" : e.getMessage()));255 Thread.currentThread().interrupt();256 }257 PlayerLoginEvent playerLoginEvent = new PlayerLoginEvent(player, address.getHostString(), address.getAddress());258 Bukkit.getPluginManager().callEvent(playerLoginEvent);259 Component joinMessage = MiniMessage.miniMessage()260 .deserialize("<name> has joined the Server!", Placeholder.component("name", player.displayName()));261 PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(player, joinMessage);262 Bukkit.getPluginManager().callEvent(playerJoinEvent);263 if (isWhitelistEnabled && !whitelistedPlayers.contains(player))264 {265 PlayerConnectionCloseEvent playerConnectionCloseEvent =266 new PlayerConnectionCloseEvent(player.getUniqueId(),267 player.getName(),268 player.getAddress().getAddress(),269 false);270 getPluginManager().callEvent(playerConnectionCloseEvent);271 playerList.disconnectPlayer(player);272 return;273 }274 player.setLastPlayed(getCurrentServerTime());275 registerEntity(player);276 }277 /**278 * Creates a random player and adds it.279 *280 * @return The player that was added.281 */282 public @NotNull PlayerMock addPlayer()283 {284 AsyncCatcher.catchOp("player add");285 PlayerMock player = playerFactory.createRandomPlayer();286 addPlayer(player);287 return player;288 }289 /**290 * Creates a player with a given name and adds it.291 *292 * @param name The name to give to the player.293 * @return The added player.294 */295 public @NotNull PlayerMock addPlayer(@NotNull String name)296 {297 AsyncCatcher.catchOp("player add");298 PlayerMock player = new PlayerMock(this, name);299 addPlayer(player);300 return player;301 }302 /**303 * Set the numbers of mock players that are on this server. Note that it will remove all players that are already on304 * this server.305 *306 * @param num The number of players that are on this server.307 */308 public void setPlayers(int num)309 {310 AsyncCatcher.catchOp("set players");311 playerList.clearOnlinePlayers();312 for (int i = 0; i < num; i++)313 addPlayer();314 }315 /**316 * Set the numbers of mock offline players that are on this server. Note that even players that are online are also317 * considered offline player because an {@link OfflinePlayer} really just refers to anyone that has at some point in318 * time played on the server.319 *320 * @param num The number of players that are on this server.321 */322 public void setOfflinePlayers(int num)323 {324 AsyncCatcher.catchOp("set offline players");325 playerList.clearOfflinePlayers();326 for (PlayerMock player : getOnlinePlayers())327 {328 playerList.addPlayer(player);329 }330 for (int i = 0; i < num; i++)331 {332 OfflinePlayer player = playerFactory.createRandomOfflinePlayer();333 playerList.addOfflinePlayer(player);334 }335 }336 /**337 * Get a specific mock player. A player's number will never change between invocations of {@link #setPlayers(int)}.338 *339 * @param num The number of the player to retrieve.340 * @return The chosen player.341 */342 public @NotNull PlayerMock getPlayer(int num)343 {344 return playerList.getPlayer(num);345 }346 /**347 * Returns the {@link MockPlayerList} instance that is used by this server.348 *349 * @return The {@link MockPlayerList} instance.350 */351 public @NotNull MockPlayerList getPlayerList()352 {353 return playerList;354 }355 @Override356 public @Nullable UUID getPlayerUniqueId(@NotNull String playerName)357 {358 return playerList.getOfflinePlayer(playerName).getUniqueId();359 }360 /**361 * Adds a very simple super flat world with a given name.362 *363 * @param name The name to give to the world.364 * @return The {@link WorldMock} that has been created.365 */366 public @NotNull WorldMock addSimpleWorld(String name)367 {368 AsyncCatcher.catchOp("world creation");369 WorldMock world = new WorldMock();370 world.setName(name);371 worlds.add(world);372 return world;373 }374 /**375 * Adds the given mocked world to this server.376 *377 * @param world The world to add.378 */379 public void addWorld(WorldMock world)380 {381 AsyncCatcher.catchOp("world add");382 worlds.add(world);383 }384 /**385 * Executes a command as the console.386 *387 * @param command The command to execute.388 * @param args The arguments to pass to the commands.389 * @return The value returned by {@link Command#execute}.390 */391 public @NotNull CommandResult executeConsole(@NotNull Command command, String... args)392 {393 return execute(command, getConsoleSender(), args);394 }395 /**396 * Executes a command as the console.397 *398 * @param command The command to execute.399 * @param args The arguments to pass to the commands.400 * @return The value returned by {@link Command#execute}.401 */402 public @NotNull CommandResult executeConsole(@NotNull String command, String... args)403 {404 return executeConsole(getCommandMap().getCommand(command), args);405 }406 /**407 * Executes a command as a player.408 *409 * @param command The command to execute.410 * @param args The arguments to pass to the commands.411 * @return The value returned by {@link Command#execute}.412 */413 public @NotNull CommandResult executePlayer(@NotNull Command command, String... args)414 {415 AsyncCatcher.catchOp("command dispatch");416 if (playerList.isSomeoneOnline())417 return execute(command, getPlayer(0), args);418 else419 throw new IllegalStateException("Need at least one player to run the command");420 }421 /**422 * Executes a command as a player.423 *424 * @param command The command to execute.425 * @param args The arguments to pass to the commands.426 * @return The value returned by {@link Command#execute}.427 */428 public @NotNull CommandResult executePlayer(@NotNull String command, String... args)429 {430 return executePlayer(getCommandMap().getCommand(command), args);431 }432 /**433 * Executes a command.434 *435 * @param command The command to execute.436 * @param sender The person that executed the command.437 * @param args The arguments to pass to the commands.438 * @return The value returned by {@link Command#execute}.439 */440 public @NotNull CommandResult execute(@NotNull Command command, CommandSender sender, String... args)441 {442 AsyncCatcher.catchOp("command dispatch");443 if (!(sender instanceof MessageTarget))444 {445 throw new IllegalArgumentException("Only a MessageTarget can be the sender of the command");446 }447 boolean status = command.execute(sender, command.getName(), args);448 return new CommandResult(status, (MessageTarget) sender);449 }450 /**451 * Executes a command.452 *453 * @param command The command to execute.454 * @param sender The person that executed the command.455 * @param args The arguments to pass to the commands.456 * @return The value returned by {@link Command#execute}.457 */458 public @NotNull CommandResult execute(@NotNull String command, CommandSender sender, String... args)459 {460 AsyncCatcher.catchOp("command dispatch");461 return execute(getCommandMap().getCommand(command), sender, args);462 }463 @Override464 public @NotNull String getName()465 {466 return "ServerMock";467 }468 @Override469 public @NotNull String getVersion()470 {471 return String.format("MockBukkit (MC: %s)", getMinecraftVersion());472 }473 @Override474 public @NotNull String getBukkitVersion()475 {476 Preconditions.checkNotNull(this.buildProperties, "Failed to load build properties!");477 String apiVersion = buildProperties.getProperty("full-api-version");478 Preconditions.checkNotNull(apiVersion, "Failed to get full-api-version from the build properties!");479 return apiVersion;480 }481 @Override482 public @NotNull String getMinecraftVersion()483 {484 return this.getBukkitVersion().split("-")[0];485 }486 @Override487 public @NotNull Collection<? extends PlayerMock> getOnlinePlayers()488 {489 return playerList.getOnlinePlayers();490 }491 @Override492 public OfflinePlayer @NotNull [] getOfflinePlayers()493 {494 return playerList.getOfflinePlayers();495 }496 @Override497 public @Nullable OfflinePlayer getOfflinePlayerIfCached(@NotNull String name)498 {499 //TODO Auto-generated method stub500 throw new UnimplementedOperationException();501 }502 @Override503 public Player getPlayer(@NotNull String name)504 {505 return playerList.getPlayer(name);506 }507 @Override508 public Player getPlayerExact(@NotNull String name)509 {510 return playerList.getPlayerExact(name);511 }512 @Override513 public @NotNull List<Player> matchPlayer(@NotNull String name)514 {515 return playerList.matchPlayer(name);516 }517 @Override518 public Player getPlayer(@NotNull UUID id)519 {520 return playerList.getPlayer(id);521 }522 @Override523 public @NotNull PluginManagerMock getPluginManager()524 {525 return pluginManager;526 }527 @NotNull528 public MockCommandMap getCommandMap()529 {530 return commandMap;531 }532 @Override533 public PluginCommand getPluginCommand(@NotNull String name)534 {535 Command command = getCommandMap().getCommand(name);536 return command instanceof PluginCommand ? (PluginCommand) command : null;537 }538 @Override539 public @NotNull Logger getLogger()540 {541 return logger;542 }543 @Override544 public @NotNull ConsoleCommandSenderMock getConsoleSender()545 {546 if (consoleSender == null)547 {548 consoleSender = new ConsoleCommandSenderMock();549 }550 return consoleSender;551 }552 @Override553 public @NotNull CommandSender createCommandSender(@NotNull Consumer<? super Component> feedback)554 {555 //TODO Auto-generated method stub556 throw new UnimplementedOperationException();557 }558 @NotNull559 @Deprecated560 public InventoryMock createInventory(InventoryHolder owner, @NotNull InventoryType type, String title, int size)561 {562 if (!type.isCreatable())563 {564 throw new IllegalArgumentException("Inventory Type is not creatable!");565 }566 switch (type)567 {568 case CHEST:569 return new ChestInventoryMock(owner, size > 0 ? size : 9 * 3);570 case DISPENSER:571 return new DispenserInventoryMock(owner);572 case DROPPER:573 return new DropperInventoryMock(owner);574 case PLAYER:575 if (owner instanceof HumanEntity)576 {577 return new PlayerInventoryMock((HumanEntity) owner);578 }579 else580 {581 throw new IllegalArgumentException("Cannot create a Player Inventory for: " + owner);582 }583 case ENDER_CHEST:584 return new EnderChestInventoryMock(owner);585 case HOPPER:586 return new HopperInventoryMock(owner);587 case SHULKER_BOX:588 return new ShulkerBoxInventoryMock(owner);589 case BARREL:590 return new BarrelInventoryMock(owner);591 case LECTERN:592 return new LecternInventoryMock(owner);593 case GRINDSTONE:594 return new GrindstoneInventoryMock(owner);595 case STONECUTTER:596 return new StonecutterInventoryMock(owner);597 case CARTOGRAPHY:598 return new CartographyInventoryMock(owner);599 case SMOKER, FURNACE, BLAST_FURNACE:600 return new FurnaceInventoryMock(owner);601 case LOOM:602 return new LoomInventoryMock(owner);603 case ANVIL:604 return new AnvilInventoryMock(owner);605 case SMITHING:606 return new SmithingInventoryMock(owner);607 case BEACON:608 return new BeaconInventoryMock(owner);609 case WORKBENCH:610 return new WorkbenchInventoryMock(owner);611 case ENCHANTING:612 return new EnchantingInventoryMock(owner);613 case BREWING:614 return new BrewerInventoryMock(owner);615 default:616 throw new UnimplementedOperationException("Inventory type not yet supported");617 }618 }619 @Override620 public @NotNull InventoryMock createInventory(InventoryHolder owner, @NotNull InventoryType type)621 {622 return createInventory(owner, type, "Inventory");623 }624 @Override625 public @NotNull InventoryMock createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type, @NotNull Component title)626 {627 //TODO Auto-generated method stub628 throw new UnimplementedOperationException();629 }630 @Override631 @Deprecated632 public @NotNull InventoryMock createInventory(InventoryHolder owner, @NotNull InventoryType type, String title)633 {634 return createInventory(owner, type, title, -1);635 }636 @Override637 public @NotNull InventoryMock createInventory(InventoryHolder owner, int size)638 {639 return createInventory(owner, size, "Inventory");640 }641 @Override642 public @NotNull InventoryMock createInventory(@Nullable InventoryHolder owner, int size, @NotNull Component title) throws IllegalArgumentException643 {644 //TODO Auto-generated method stub645 throw new UnimplementedOperationException();646 }647 @Override648 @Deprecated649 public @NotNull InventoryMock createInventory(InventoryHolder owner, int size, String title)650 {651 return createInventory(owner, InventoryType.CHEST, title, size);652 }653 @Override654 public @NotNull Merchant createMerchant(@Nullable Component title)655 {656 //TODO Auto-generated method stub657 throw new UnimplementedOperationException();658 }659 @Override660 public @NotNull ItemFactoryMock getItemFactory()661 {662 return factory;663 }664 @Override665 public @NotNull List<World> getWorlds()666 {667 return new ArrayList<>(worlds);668 }669 @Override670 public World getWorld(String name)671 {672 return worlds.stream().filter(world -> world.getName().equals(name)).findAny().orElse(null);673 }674 @Override675 public World getWorld(UUID uid)676 {677 return worlds.stream().filter(world -> world.getUID().equals(uid)).findAny().orElse(null);678 }679 @Override680 public @Nullable World getWorld(@NotNull NamespacedKey worldKey)681 {682 // TODO Auto-generated method stub683 throw new UnimplementedOperationException();684 }685 @NotNull686 @Override687 public WorldBorder createWorldBorder()688 {689 // TODO Auto-generated method stub690 throw new UnimplementedOperationException();691 }692 @Override693 public @NotNull BukkitSchedulerMock getScheduler()694 {695 return scheduler;696 }697 @Override698 public int getMaxPlayers()699 {700 return playerList.getMaxPlayers();701 }702 @Override703 public void setMaxPlayers(int maxPlayers)704 {705 playerList.setMaxPlayers(maxPlayers);706 }707 @Override708 public @NotNull Set<String> getIPBans()709 {710 return this.playerList.getIPBans().getBanEntries().stream().map(BanEntry::getTarget)711 .collect(Collectors.toSet());712 }713 @Override714 public void banIP(@NotNull String address)715 {716 this.playerList.getIPBans().addBan(address, null, null, null);717 }718 @Override719 public void unbanIP(@NotNull String address)720 {721 this.playerList.getIPBans().pardon(address);722 }723 @Override724 public @NotNull BanList getBanList(@NotNull Type type)725 {726 return switch (type)727 {728 case IP -> playerList.getIPBans();729 case NAME -> playerList.getProfileBans();730 };731 }732 @Override733 public @NotNull Set<OfflinePlayer> getOperators()734 {735 return playerList.getOperators();736 }737 @Override738 public @NotNull GameMode getDefaultGameMode()739 {740 return this.defaultGameMode;741 }742 @Override743 public void setDefaultGameMode(GameMode mode)744 {745 this.defaultGameMode = mode;746 }747 @Override748 @Deprecated749 public int broadcastMessage(@NotNull String message)750 {751 Collection<? extends PlayerMock> players = getOnlinePlayers();752 for (Player player : players)753 {754 player.sendMessage(message);755 }756 return players.size();757 }758 @Override759 @Deprecated760 public int broadcast(@NotNull String message, @NotNull String permission)761 {762 Collection<? extends PlayerMock> players = getOnlinePlayers();763 int count = 0;764 for (Player player : players)765 {766 if (player.hasPermission(permission))767 {768 player.sendMessage(message);769 count++;770 }771 }772 return count;773 }774 @Override775 public int broadcast(@NotNull Component message)776 {777 Collection<? extends PlayerMock> players = getOnlinePlayers();778 for (Player player : players)779 {780 player.sendMessage(message);781 }782 return players.size();783 }784 @Override785 public int broadcast(@NotNull Component message, @NotNull String permission)786 {787 Collection<? extends PlayerMock> players = getOnlinePlayers();788 int count = 0;789 for (Player player : players)790 {791 if (player.hasPermission(permission))792 {793 player.sendMessage(message);794 count++;795 }796 }797 return count;798 }799 /**800 * Registers any classes that are serializable with the ConfigurationSerializable system of Bukkit.801 */802 public static void registerSerializables()803 {804 ConfigurationSerialization.registerClass(ItemMetaMock.class);805 }806 @Override807 public boolean addRecipe(Recipe recipe)808 {809 recipes.add(recipe);810 return true;811 }812 @Override813 public @NotNull List<Recipe> getRecipesFor(@NotNull ItemStack item)814 {815 return recipes.stream().filter(recipe ->816 {817 ItemStack result = recipe.getResult();818 // Amount is explicitly ignored here819 return result.getType() == item.getType() && result.getItemMeta().equals(item.getItemMeta());820 }).collect(Collectors.toList());821 }822 @Override823 public Recipe getRecipe(NamespacedKey key)824 {825 for (Recipe recipe : recipes)826 {827 // Seriously why can't the Recipe interface itself just extend Keyed...828 if (recipe instanceof Keyed && ((Keyed) recipe).getKey().equals(key))829 {830 return recipe;831 }832 }833 return null;834 }835 @Nullable836 @Override837 public Recipe getCraftingRecipe(@NotNull ItemStack[] craftingMatrix, @NotNull World world)838 {839 // TODO Auto-generated method stub840 throw new UnimplementedOperationException();841 }842 @NotNull843 @Override844 public ItemStack craftItem(@NotNull ItemStack[] craftingMatrix, @NotNull World world, @NotNull Player player)845 {846 // TODO Auto-generated method stub847 throw new UnimplementedOperationException();848 }849 @Override850 public boolean removeRecipe(NamespacedKey key)851 {852 Iterator<Recipe> iterator = recipeIterator();853 while (iterator.hasNext())854 {855 Recipe recipe = iterator.next();856 // Seriously why can't the Recipe interface itself just extend Keyed...857 if (recipe instanceof Keyed && ((Keyed) recipe).getKey().equals(key))858 {859 iterator.remove();860 return true;861 }862 }863 return false;864 }865 @Override866 public @NotNull Iterator<Recipe> recipeIterator()867 {868 return recipes.iterator();869 }870 @Override871 public void clearRecipes()872 {873 recipes.clear();874 }875 @Override876 public boolean dispatchCommand(@NotNull CommandSender sender, @NotNull String commandLine)877 {878 AsyncCatcher.catchOp("command dispatch");879 String[] commands = commandLine.split(" ");880 String commandLabel = commands[0];881 String[] args = Arrays.copyOfRange(commands, 1, commands.length);882 Command command = getCommandMap().getCommand(commandLabel);883 if (command != null)884 {885 return command.execute(sender, commandLabel, args);886 }887 else888 {889 return false;890 }891 }892 public @NotNull List<String> getCommandTabComplete(@NotNull CommandSender sender, @NotNull String commandLine)893 {894 AsyncCatcher.catchOp("command tabcomplete");895 int idx = commandLine.indexOf(' ');896 String commandLabel = commandLine.substring(0, idx);897 String[] args = commandLine.substring(idx + 1).split(" ", -1);898 Command command = getCommandMap().getCommand(commandLabel);899 if (command != null)900 {901 return command.tabComplete(sender, commandLabel, args);902 }903 else904 {905 return Collections.emptyList();906 }907 }908 @Override909 public @NotNull HelpMapMock getHelpMap()910 {911 return helpMap;912 }913 @Override914 public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte[] message)915 {916 StandardMessenger.validatePluginMessage(this.getMessenger(), source, channel, message);917 for (Player player : this.getOnlinePlayers())918 {919 player.sendPluginMessage(source, channel, message);920 }921 }922 @Override923 public @NotNull Set<String> getListeningPluginChannels()924 {925 Set<String> result = new HashSet<>();926 for (Player player : this.getOnlinePlayers())927 {928 result.addAll(player.getListeningPluginChannels());929 }930 return result;931 }932 @Override933 public int getPort()934 {935 // TODO Auto-generated method stub936 throw new UnimplementedOperationException();937 }938 @Override939 public int getViewDistance()940 {941 // TODO Auto-generated method stub942 throw new UnimplementedOperationException();943 }944 @Override945 public @NotNull String getIp()946 {947 // TODO Auto-generated method stub948 throw new UnimplementedOperationException();949 }950 @Override951 public @NotNull String getWorldType()952 {953 // TODO Auto-generated method stub954 throw new UnimplementedOperationException();955 }956 @Override957 public boolean getGenerateStructures()958 {959 // TODO Auto-generated method stub960 throw new UnimplementedOperationException();961 }962 @Override963 public boolean getAllowEnd()964 {965 // TODO Auto-generated method stub966 throw new UnimplementedOperationException();967 }968 @Override969 public boolean getAllowNether()970 {971 // TODO Auto-generated method stub972 throw new UnimplementedOperationException();973 }974 @NotNull975 @Override976 public String getResourcePack()977 {978 // TODO Auto-generated method stub979 throw new UnimplementedOperationException();980 }981 @NotNull982 @Override983 public String getResourcePackHash()984 {985 // TODO Auto-generated method stub986 throw new UnimplementedOperationException();987 }988 @NotNull989 @Override990 public String getResourcePackPrompt()991 {992 // TODO Auto-generated method stub993 throw new UnimplementedOperationException();994 }995 @Override996 public boolean isResourcePackRequired()997 {998 // TODO Auto-generated method stub999 throw new UnimplementedOperationException();1000 }1001 @Override1002 public boolean hasWhitelist()1003 {1004 return this.isWhitelistEnabled;1005 }1006 @Override1007 public void setWhitelist(boolean value)1008 {1009 this.isWhitelistEnabled = value;1010 WhitelistToggleEvent event = new WhitelistToggleEvent(value);1011 this.getPluginManager().callEvent(event);1012 }1013 @Override1014 public boolean isWhitelistEnforced()1015 {1016 return this.isWhitelistEnforced;1017 }1018 @Override1019 public void setWhitelistEnforced(boolean value)1020 {1021 this.isWhitelistEnforced = value;1022 }1023 @Override1024 public @NotNull Set<OfflinePlayer> getWhitelistedPlayers()1025 {1026 return this.whitelistedPlayers;1027 }1028 @Override1029 public void reloadWhitelist()1030 {1031 //Pretend we load the Whitelist from Disk1032 if (!isWhitelistEnforced && isWhitelistEnabled)1033 {1034 return;1035 }1036 MockBukkit.getMock().getOnlinePlayers().forEach(p ->1037 {1038 if (!MockBukkit.getMock().getWhitelistedPlayers().contains(p))1039 {1040 p.kick();1041 }1042 });1043 }1044 @Override1045 public @NotNull String getUpdateFolder()1046 {1047 // TODO Auto-generated method stub1048 throw new UnimplementedOperationException();1049 }1050 @Override1051 public @NotNull File getUpdateFolderFile()1052 {1053 // TODO Auto-generated method stub1054 throw new UnimplementedOperationException();1055 }1056 @Override1057 public long getConnectionThrottle()1058 {1059 // TODO Auto-generated method stub1060 throw new UnimplementedOperationException();1061 }1062 @Override1063 @Deprecated1064 public int getTicksPerAnimalSpawns()1065 {1066 // TODO Auto-generated method stub1067 throw new UnimplementedOperationException();1068 }1069 @Override1070 @Deprecated1071 public int getTicksPerMonsterSpawns()1072 {1073 // TODO Auto-generated method stub1074 throw new UnimplementedOperationException();1075 }1076 @Override1077 public @NotNull ServicesManagerMock getServicesManager()1078 {1079 return servicesManager;1080 }1081 @Override1082 public World createWorld(@NotNull WorldCreator creator)1083 {1084 WorldMock world = new WorldMock(creator);1085 addWorld(world);1086 return world;1087 }1088 @Override1089 public boolean unloadWorld(String name, boolean save)1090 {1091 // TODO Auto-generated method stub1092 throw new UnimplementedOperationException();1093 }1094 @Override1095 public boolean unloadWorld(World world, boolean save)1096 {1097 // TODO Auto-generated method stub1098 throw new UnimplementedOperationException();1099 }1100 @Override1101 public @NotNull MapViewMock createMap(@NotNull World world)1102 {1103 MapViewMock mapView = new MapViewMock(world, nextMapId++);1104 mapViews.put(mapView.getId(), mapView);1105 new MapInitializeEvent(mapView).callEvent();1106 return mapView;1107 }1108 @Override1109 public void reload()1110 {1111 // TODO Auto-generated method stub1112 throw new UnimplementedOperationException();1113 }1114 @Override1115 public void reloadData()1116 {1117 // TODO Auto-generated method stub1118 throw new UnimplementedOperationException();1119 }1120 @Override1121 public void savePlayers()1122 {1123 // TODO Auto-generated method stub1124 throw new UnimplementedOperationException();1125 }1126 @Override1127 public void resetRecipes()1128 {1129 // TODO Auto-generated method stub1130 throw new UnimplementedOperationException();1131 }1132 @Override1133 public @NotNull Map<String, String[]> getCommandAliases()1134 {1135 // TODO Auto-generated method stub1136 throw new UnimplementedOperationException();1137 }1138 @Override1139 public int getSpawnRadius()1140 {1141 return spawnRadius;1142 }1143 @Override1144 public void setSpawnRadius(int spawnRadius)1145 {1146 this.spawnRadius = spawnRadius;1147 }1148 @Override1149 public boolean shouldSendChatPreviews()1150 {1151 // TODO Auto-generated method stub1152 throw new UnimplementedOperationException();1153 }1154 @Override1155 public boolean isEnforcingSecureProfiles()1156 {1157 // TODO Auto-generated method stub1158 throw new UnimplementedOperationException();1159 }1160 @Override1161 public boolean getOnlineMode()1162 {1163 // TODO Auto-generated method stub1164 throw new UnimplementedOperationException();1165 }1166 @Override1167 public boolean getAllowFlight()1168 {1169 // TODO Auto-generated method stub1170 throw new UnimplementedOperationException();1171 }1172 @Override1173 public boolean isHardcore()1174 {1175 // TODO Auto-generated method stub1176 throw new UnimplementedOperationException();1177 }1178 @Override1179 public void shutdown()1180 {1181 // TODO Auto-generated method stub1182 throw new UnimplementedOperationException();1183 }1184 @Override1185 @Deprecated1186 public @NotNull OfflinePlayer getOfflinePlayer(@NotNull String name)1187 {1188 return playerList.getOfflinePlayer(name);1189 }1190 @Override1191 public @NotNull OfflinePlayer getOfflinePlayer(@NotNull UUID id)1192 {1193 OfflinePlayer player = playerList.getOfflinePlayer(id);1194 if (player != null)1195 {1196 return player;1197 }1198 else1199 {1200 return playerFactory.createOfflinePlayer(id);1201 }1202 }1203 @Override1204 public @NotNull Set<OfflinePlayer> getBannedPlayers()1205 {1206 return this.getBanList(Type.NAME)1207 .getBanEntries()1208 .stream()1209 .map(banEntry -> getOfflinePlayer(banEntry.getTarget()))1210 .collect(Collectors.toSet());1211 }1212 @Override1213 public @NotNull File getWorldContainer()1214 {1215 // TODO Auto-generated method stub1216 throw new UnimplementedOperationException();1217 }1218 @Override1219 public @NotNull Messenger getMessenger()1220 {1221 return this.messenger;1222 }1223 @Override1224 @Deprecated1225 public @NotNull Merchant createMerchant(String title)1226 {1227 // TODO Auto-generated method stub1228 throw new UnimplementedOperationException();1229 }1230 @Override1231 public int getMaxChainedNeighborUpdates()1232 {1233 //TODO Auto-generated method stub1234 throw new UnimplementedOperationException();1235 }1236 @Override1237 @Deprecated1238 public int getMonsterSpawnLimit()1239 {1240 // TODO Auto-generated method stub1241 throw new UnimplementedOperationException();1242 }1243 @Override1244 @Deprecated1245 public int getAnimalSpawnLimit()1246 {1247 // TODO Auto-generated method stub1248 throw new UnimplementedOperationException();1249 }1250 @Override1251 @Deprecated1252 public int getWaterAnimalSpawnLimit()1253 {1254 // TODO Auto-generated method stub1255 throw new UnimplementedOperationException();1256 }1257 @Override1258 @Deprecated1259 public int getAmbientSpawnLimit()1260 {1261 // TODO Auto-generated method stub1262 throw new UnimplementedOperationException();1263 }1264 @Override1265 public boolean isPrimaryThread()1266 {1267 return this.isOnMainThread();1268 }1269 @Override1270 public @NotNull Component motd()1271 {1272 return MOTD;1273 }1274 @Override1275 @Deprecated1276 public @NotNull String getMotd()1277 {1278 return LegacyComponentSerializer.legacySection().serialize(MOTD);1279 }1280 @Override1281 public @Nullable Component shutdownMessage()1282 {1283 // TODO Auto-generated method stub1284 throw new UnimplementedOperationException();1285 }1286 @Override1287 @Deprecated1288 public String getShutdownMessage()1289 {1290 // TODO Auto-generated method stub1291 throw new UnimplementedOperationException();1292 }1293 /**1294 * Sets the return value of {@link #getWarningState}.1295 *1296 * @param warningState The {@link WarningState} to set.1297 */1298 public void setWarningState(@NotNull WarningState warningState)1299 {1300 Preconditions.checkNotNull(warningState, "warningState cannot be null");1301 this.warningState = warningState;1302 }1303 @Override1304 public @NotNull WarningState getWarningState()1305 {1306 return this.warningState;1307 }1308 @Override1309 public @NotNull ScoreboardManagerMock getScoreboardManager()1310 {1311 return scoreboardManager;1312 }1313 @Override1314 public @NotNull Criteria getScoreboardCriteria(@NotNull String name)1315 {1316 // TODO Auto-generated method stub1317 throw new UnimplementedOperationException();1318 }1319 /**1320 * Sets the return value of {@link #getServerIcon()}.1321 *1322 * @param serverIcon The icon to set.1323 */1324 public void setServerIcon(CachedServerIconMock serverIcon)1325 {1326 this.serverIcon = serverIcon;1327 }1328 @Override1329 public CachedServerIconMock getServerIcon()1330 {1331 return this.serverIcon;1332 }1333 @Override1334 public @NotNull CachedServerIconMock loadServerIcon(@NotNull File file) throws IOException1335 {1336 Preconditions.checkNotNull(file, "File cannot be null");1337 Preconditions.checkArgument(file.isFile(), file + " isn't a file");1338 return loadServerIcon(ImageIO.read(file));1339 }1340 @Override1341 public @NotNull CachedServerIconMock loadServerIcon(@NotNull BufferedImage image) throws IOException1342 {1343 Preconditions.checkNotNull(image, "Image cannot be null");1344 Preconditions.checkArgument(image.getWidth() == 64, "Image must be 64 pixels wide");1345 Preconditions.checkArgument(image.getHeight() == 64, "Image must be 64 pixels high");1346 ByteArrayOutputStream out = new ByteArrayOutputStream();1347 ImageIO.write(image, "PNG", out);1348 String encoded = Base64.getEncoder().encodeToString(out.toByteArray());1349 return new CachedServerIconMock(CachedServerIconMock.PNG_BASE64_PREFIX + encoded);1350 }1351 @Override1352 public void setIdleTimeout(int threshold)1353 {1354 // TODO Auto-generated method stub1355 throw new UnimplementedOperationException();1356 }1357 @Override1358 public int getIdleTimeout()1359 {1360 // TODO Auto-generated method stub1361 throw new UnimplementedOperationException();1362 }1363 @Override...

Full Screen

Full Screen

Source:ServerMockTest.java Github

copy

Full Screen

...798 BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);799 Graphics2D g = image.createGraphics();800 g.drawOval(0, 0, 64, 64);801 g.dispose();802 CachedServerIconMock icon = server.loadServerIcon(image);803 byte[] decodedBase64 = Base64.getDecoder().decode(icon.getData().replace(CachedServerIconMock.PNG_BASE64_PREFIX, ""));804 BufferedImage decodedImage = ImageIO.read(new ByteArrayInputStream(decodedBase64));805 for (int x = 0; x < 64; x++)806 {807 for (int y = 0; y < 64; y++)808 {809 assertEquals(image.getRGB(x, y), decodedImage.getRGB(x, y));810 }811 }812 }813}814class TestRecipe implements Recipe815{816 private final @NotNull ItemStack result;817 public TestRecipe(@NotNull ItemStack result)...

Full Screen

Full Screen

Source:CachedServerIconMockTest.java Github

copy

Full Screen

...4import org.junit.jupiter.api.Test;5import static org.junit.jupiter.api.Assertions.assertEquals;6import static org.junit.jupiter.api.Assertions.assertNotNull;7import static org.junit.jupiter.api.Assertions.assertNull;8class CachedServerIconMockTest9{10 private ServerMock mock;11 @BeforeEach12 public void setUp()13 {14 mock = MockBukkit.mock();15 }16 @AfterEach17 public void teardown()18 {19 MockBukkit.unmock();20 }21 @Test22 void constructor_NotNull_SetsData()23 {24 CachedServerIconMock icon = new CachedServerIconMock(null);25 assertNull(icon.getData());26 }27 @Test28 void constructor_WithData_SetsData()29 {30 CachedServerIconMock icon = new CachedServerIconMock("mmm yes data");31 assertNotNull(icon.getData());32 assertEquals("mmm yes data", icon.getData());33 }34}

Full Screen

Full Screen

CachedServerIconMock

Using AI Code Generation

copy

Full Screen

1ServerMock server = new ServerMock();2CachedServerIconMock icon = new CachedServerIconMock();3server.setServerIcon(icon);4server.getServerIcon();5ServerMock server = new ServerMock();6CachedServerIconMock icon = new CachedServerIconMock();7server.setServerIcon(icon);8server.getServerIcon();9ServerMock server = new ServerMock();10CachedServerIconMock icon = new CachedServerIconMock();11server.setServerIcon(icon);12server.getServerIcon();13ServerMock server = new ServerMock();14CachedServerIconMock icon = new CachedServerIconMock();15server.setServerIcon(icon);16server.getServerIcon();17ServerMock server = new ServerMock();18CachedServerIconMock icon = new CachedServerIconMock();19server.setServerIcon(icon);20server.getServerIcon();21ServerMock server = new ServerMock();22CachedServerIconMock icon = new CachedServerIconMock();23server.setServerIcon(icon);24server.getServerIcon();25ServerMock server = new ServerMock();26CachedServerIconMock icon = new CachedServerIconMock();27server.setServerIcon(icon);28server.getServerIcon();29ServerMock server = new ServerMock();30CachedServerIconMock icon = new CachedServerIconMock();31server.setServerIcon(icon);32server.getServerIcon();33ServerMock server = new ServerMock();

Full Screen

Full Screen

CachedServerIconMock

Using AI Code Generation

copy

Full Screen

1public class CachedServerIconMockTest {2 public void testCachedServerIconMock() {3 ServerMock server = MockBukkit.mock();4 CachedServerIconMock icon = new CachedServerIconMock();5 server.setServerIcon(icon);6 Assert.assertEquals(icon, server.getServerIcon());7 }8}9public class CachedServerIconMockTest {10 public void testCachedServerIconMock() {11 ServerMock server = MockBukkit.mock();12 CachedServerIconMock icon = new CachedServerIconMock();13 server.setServerIcon(icon);14 Assert.assertEquals(icon, server.getServerIcon());15 }16}17public class CachedServerIconMockTest {18 public void testCachedServerIconMock() {19 ServerMock server = MockBukkit.mock();20 CachedServerIconMock icon = new CachedServerIconMock();21 server.setServerIcon(icon);22 Assert.assertEquals(icon, server.getServerIcon());23 }24}25public class CachedServerIconMockTest {26 public void testCachedServerIconMock() {27 ServerMock server = MockBukkit.mock();28 CachedServerIconMock icon = new CachedServerIconMock();29 server.setServerIcon(icon);30 Assert.assertEquals(icon, server.getServerIcon());31 }32}33public class CachedServerIconMockTest {34 public void testCachedServerIconMock() {35 ServerMock server = MockBukkit.mock();36 CachedServerIconMock icon = new CachedServerIconMock();37 server.setServerIcon(icon);38 Assert.assertEquals(icon, server.getServerIcon());39 }40}41public class CachedServerIconMockTest {42 public void testCachedServerIconMock() {

Full Screen

Full Screen

CachedServerIconMock

Using AI Code Generation

copy

Full Screen

1import org.junit.jupiter.api.AfterEach;2import org.junit.jupiter.api.BeforeEach;3import org.junit.jupiter.api.Test;4import org.junit.jupiter.api.extension.ExtendWith;5import org.mockito.Mockito;6import org.mockito.junit.jupiter.MockitoExtension;7import be.seeseemelk.mockbukkit.MockBukkit;8import be.seeseemelk.mockbukkit.ServerMock;9import be.seeseemelk.mockbukkit.entity.PlayerMock;10import be.seeseemelk.mockbukkit.entity.PlayerMockFactory;11import be.seeseemelk.mockbukkit.entity.PlayerMockFactory.PlayerOptions;12import java.awt.image.BufferedImage;13import java.io.File;14import java.io.IOException;15import javax.imageio.ImageIO;16import org.bukkit.entity.Player;17import org.bukkit.event.player.PlayerJoinEvent;18import org.bukkit.event.player.PlayerQuitEvent;19import org.bukkit.plugin.Plugin;20import org.bukkit.plugin.PluginManager;21import org.bukkit.plugin.java.JavaPlugin;22import org.junit.jupiter.api.Assertions;23@ExtendWith(MockitoExtension.class)24{25 private JavaPlugin plugin;26 private ServerMock server;27 private PluginManager pluginManager;28 private PlayerMockFactory playerFactory;29 private PlayerOptions options;30 private PlayerMock player;31 public void setUp()32 {33 plugin = MockBukkit.load(JavaPlugin.class);34 server = MockBukkit.getMock();35 pluginManager = server.getPluginManager();36 playerFactory = server.getPlayerFactory();37 options = playerFactory.getOptions();38 player = playerFactory.createPlayer(options);39 }40 public void tearDown()41 {42 MockBukkit.unmock();43 }44 public void testServerIcon()45 {46 File file = new File("test.png");47 Assertions.assertTrue(file.exists());48 BufferedImage image = null;49 {50 image = ImageIO.read(file);51 }52 catch (IOException e)53 {54 Assertions.fail(e);55 }56 server.setServerIcon(image);57 server.addPlayer(player);58 Mockito.verify(player).setPlayerListHeaderFooter(Mockito.any(), Mockito.any());59 }60}

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.

Run MockBukkit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ServerMock

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful