How to use serialize method of be.seeseemelk.mockbukkit.profile.PlayerProfileMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.profile.PlayerProfileMock.serialize

Source:ServerMock.java Github

copy

Full Screen

...53import net.kyori.adventure.text.Component;54import net.kyori.adventure.text.format.NamedTextColor;55import net.kyori.adventure.text.minimessage.MiniMessage;56import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;57import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;58import net.md_5.bungee.api.chat.BaseComponent;59import org.apache.commons.lang3.StringUtils;60import org.bukkit.BanEntry;61import org.bukkit.BanList;62import org.bukkit.BanList.Type;63import org.bukkit.Bukkit;64import org.bukkit.Color;65import org.bukkit.GameMode;66import org.bukkit.Keyed;67import org.bukkit.Location;68import org.bukkit.Material;69import org.bukkit.NamespacedKey;70import org.bukkit.OfflinePlayer;71import org.bukkit.Registry;72import org.bukkit.Server;73import org.bukkit.StructureType;74import org.bukkit.Tag;75import org.bukkit.Warning.WarningState;76import org.bukkit.World;77import org.bukkit.WorldBorder;78import org.bukkit.WorldCreator;79import org.bukkit.advancement.Advancement;80import org.bukkit.block.data.BlockData;81import org.bukkit.boss.BarColor;82import org.bukkit.boss.BarFlag;83import org.bukkit.boss.BarStyle;84import org.bukkit.boss.BossBar;85import org.bukkit.boss.KeyedBossBar;86import org.bukkit.command.Command;87import org.bukkit.command.CommandSender;88import org.bukkit.command.PluginCommand;89import org.bukkit.configuration.file.YamlConfiguration;90import org.bukkit.configuration.serialization.ConfigurationSerialization;91import org.bukkit.entity.Entity;92import org.bukkit.entity.HumanEntity;93import org.bukkit.entity.Player;94import org.bukkit.entity.SpawnCategory;95import org.bukkit.event.inventory.InventoryType;96import org.bukkit.event.player.AsyncPlayerPreLoginEvent;97import org.bukkit.event.player.PlayerJoinEvent;98import org.bukkit.event.player.PlayerLoginEvent;99import org.bukkit.event.server.MapInitializeEvent;100import org.bukkit.generator.ChunkGenerator.ChunkData;101import org.bukkit.inventory.InventoryHolder;102import org.bukkit.inventory.ItemStack;103import org.bukkit.inventory.Merchant;104import org.bukkit.inventory.Recipe;105import org.bukkit.loot.LootTable;106import org.bukkit.plugin.Plugin;107import org.bukkit.plugin.messaging.Messenger;108import org.bukkit.plugin.messaging.StandardMessenger;109import org.bukkit.potion.PotionBrewer;110import org.bukkit.potion.PotionEffectType;111import org.bukkit.scoreboard.Criteria;112import org.bukkit.structure.StructureManager;113import org.jetbrains.annotations.NotNull;114import org.jetbrains.annotations.Nullable;115import javax.imageio.ImageIO;116import java.awt.image.BufferedImage;117import java.io.ByteArrayOutputStream;118import java.io.File;119import java.io.IOException;120import java.io.InputStream;121import java.net.InetSocketAddress;122import java.util.ArrayList;123import java.util.Arrays;124import java.util.Base64;125import java.util.Collection;126import java.util.Collections;127import java.util.HashMap;128import java.util.HashSet;129import java.util.Iterator;130import java.util.LinkedHashSet;131import java.util.LinkedList;132import java.util.List;133import java.util.Locale;134import java.util.Map;135import java.util.Properties;136import java.util.Set;137import java.util.UUID;138import java.util.concurrent.CountDownLatch;139import java.util.function.Consumer;140import java.util.logging.Level;141import java.util.logging.LogManager;142import java.util.logging.Logger;143import java.util.stream.Collectors;144public class ServerMock extends Server.Spigot implements Server145{146 private static final Component MOTD = Component.text("A Minecraft Server");147 private static final Component NO_PERMISSION = Component.text("I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.", NamedTextColor.RED);148 private final Properties buildProperties = new Properties();149 private final Logger logger = Logger.getLogger("ServerMock");150 private final Thread mainThread = Thread.currentThread();151 private final MockUnsafeValues unsafe = new MockUnsafeValues();152 private final Map<String, TagRegistry> materialTags = new HashMap<>();153 private final Set<EntityMock> entities = new HashSet<>();154 private final List<World> worlds = new ArrayList<>();155 private final List<Recipe> recipes = new LinkedList<>();156 private final Map<NamespacedKey, KeyedBossBarMock> bossBars = new HashMap<>();157 private final ItemFactoryMock factory = new ItemFactoryMock();158 private final PlayerMockFactory playerFactory = new PlayerMockFactory(this);159 private final PluginManagerMock pluginManager = new PluginManagerMock(this);160 private final ScoreboardManagerMock scoreboardManager = new ScoreboardManagerMock();161 private final BukkitSchedulerMock scheduler = new BukkitSchedulerMock();162 private final ServicesManagerMock servicesManager = new ServicesManagerMock();163 private final MockPlayerList playerList = new MockPlayerList();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 @Override1364 public @NotNull ChunkData createChunkData(@NotNull World world)1365 {1366 Preconditions.checkNotNull(world, "World cannot be null");1367 return new MockChunkData(world);1368 }1369 @Override1370 @Deprecated(forRemoval = true)1371 public @NotNull ChunkData createVanillaChunkData(@NotNull World world, int x, int z)1372 {1373 //TODO Auto-generated method stub1374 throw new UnimplementedOperationException();1375 }1376 @Override1377 public @NotNull BossBar createBossBar(@NotNull String title, @NotNull BarColor color, @NotNull BarStyle style, BarFlag... flags)1378 {1379 return new BossBarMock(title, color, style, flags);1380 }1381 @Override1382 public @Nullable Entity getEntity(@NotNull UUID uuid)1383 {1384 Preconditions.checkNotNull(uuid, "uuid cannot be null");1385 for (EntityMock entity : entities)1386 {1387 if (entity.getUniqueId().equals(uuid))1388 {1389 return entity;1390 }1391 }1392 return null;1393 }1394 @Override1395 public @NotNull double[] getTPS()1396 {1397 // TODO Auto-generated method stub1398 throw new UnimplementedOperationException();1399 }1400 @Override1401 public @NotNull long[] getTickTimes()1402 {1403 // TODO Auto-generated method stub1404 throw new UnimplementedOperationException();1405 }1406 @Override1407 public double getAverageTickTime()1408 {1409 // TODO Auto-generated method stub1410 throw new UnimplementedOperationException();1411 }1412 @Override1413 public Advancement getAdvancement(NamespacedKey key)1414 {1415 // TODO Auto-generated method stub1416 throw new UnimplementedOperationException();1417 }1418 @Override1419 public @NotNull Iterator<Advancement> advancementIterator()1420 {1421 // TODO Auto-generated method stub1422 throw new UnimplementedOperationException();1423 }1424 @Override1425 @Deprecated1426 public @NotNull MockUnsafeValues getUnsafe()1427 {1428 return unsafe;1429 }1430 @Override1431 public @NotNull BlockData createBlockData(@NotNull Material material)1432 {1433 Preconditions.checkNotNull(material, "Must provide material");1434 return BlockDataMock.mock(material);1435 }1436 @Override1437 public @NotNull BlockData createBlockData(@NotNull Material material, @Nullable Consumer<BlockData> consumer)1438 {1439 BlockData blockData = createBlockData(material);1440 if (consumer != null)1441 {1442 consumer.accept(blockData);1443 }1444 return blockData;1445 }1446 @Override1447 public @NotNull BlockData createBlockData(String data)1448 {1449 // TODO Auto-generated method stub1450 throw new UnimplementedOperationException();1451 }1452 @Override1453 public @NotNull BlockData createBlockData(Material material, String data)1454 {1455 // TODO Auto-generated method stub1456 throw new UnimplementedOperationException();1457 }1458 /**1459 * This creates a new Mock {@link Tag} for the {@link Material} class.<br>1460 * Call this in advance before you are gonna access {@link #getTag(String, NamespacedKey, Class)} or any of the1461 * constants defined in {@link Tag}.1462 *1463 * @param key The {@link NamespacedKey} for this {@link Tag}1464 * @param registryKey The name of the {@link TagRegistry}.1465 * @param materials {@link Material Materials} which should be covered by this {@link Tag}1466 * @return The newly created {@link Tag}1467 */1468 @NotNull1469 public Tag<Material> createMaterialTag(@NotNull NamespacedKey key, @NotNull String registryKey, @NotNull Material... materials)1470 {1471 Preconditions.checkNotNull(key, "A NamespacedKey must never be null");1472 TagRegistry registry = materialTags.get(registryKey);1473 TagWrapperMock tag = new TagWrapperMock(registry, key);1474 registry.getTags().put(key, tag);1475 return tag;1476 }1477 public void addTagRegistry(@NotNull TagRegistry registry)1478 {1479 materialTags.put(registry.getRegistry(), registry);1480 }1481 @SuppressWarnings("unchecked")1482 @Override1483 public <T extends Keyed> Tag<T> getTag(String registryKey, NamespacedKey key, Class<T> clazz)1484 {1485 if (clazz == Material.class)1486 {1487 TagRegistry registry = materialTags.get(registryKey);1488 if (registry != null)1489 {1490 Tag<Material> tag = registry.getTags().get(key);1491 if (tag != null)1492 {1493 return (Tag<T>) tag;1494 }1495 }1496 }1497 // Per definition this method should return null if the given tag does not exist.1498 return null;1499 }1500 /**1501 * This registers Minecrafts default {@link PotionEffectType PotionEffectTypes}. It also prevents any new effects to1502 * be created afterwards.1503 */1504 private void createPotionEffectTypes()1505 {1506 for (PotionEffectType type : PotionEffectType.values())1507 {1508 // We probably already registered all Potion Effects1509 // otherwise this would be null1510 if (type != null)1511 {1512 // This is not perfect, but it works.1513 return;1514 }1515 }1516 registerPotionEffectType(1, "SPEED", false, 8171462);1517 registerPotionEffectType(2, "SLOWNESS", false, 5926017);1518 registerPotionEffectType(3, "HASTE", false, 14270531);1519 registerPotionEffectType(4, "MINING_FATIGUE", false, 4866583);1520 registerPotionEffectType(5, "STRENGTH", false, 9643043);1521 registerPotionEffectType(6, "INSTANT_HEALTH", true, 16262179);1522 registerPotionEffectType(7, "INSTANT_DAMAGE", true, 4393481);1523 registerPotionEffectType(8, "JUMP_BOOST", false, 2293580);1524 registerPotionEffectType(9, "NAUSEA", false, 5578058);1525 registerPotionEffectType(10, "REGENERATION", false, 13458603);1526 registerPotionEffectType(11, "RESISTANCE", false, 10044730);1527 registerPotionEffectType(12, "FIRE_RESISTANCE", false, 14981690);1528 registerPotionEffectType(13, "WATER_BREATHING", false, 3035801);1529 registerPotionEffectType(14, "INVISIBILITY", false, 8356754);1530 registerPotionEffectType(15, "BLINDNESS", false, 2039587);1531 registerPotionEffectType(16, "NIGHT_VISION", false, 2039713);1532 registerPotionEffectType(17, "HUNGER", false, 5797459);1533 registerPotionEffectType(18, "WEAKNESS", false, 4738376);1534 registerPotionEffectType(19, "POISON", false, 5149489);1535 registerPotionEffectType(20, "WITHER", false, 3484199);1536 registerPotionEffectType(21, "HEALTH_BOOST", false, 16284963);1537 registerPotionEffectType(22, "ABSORPTION", false, 2445989);1538 registerPotionEffectType(23, "SATURATION", true, 16262179);1539 registerPotionEffectType(24, "GLOWING", false, 9740385);1540 registerPotionEffectType(25, "LEVITATION", false, 13565951);1541 registerPotionEffectType(26, "LUCK", false, 3381504);1542 registerPotionEffectType(27, "UNLUCK", false, 12624973);1543 registerPotionEffectType(28, "SLOW_FALLING", false, 16773073);1544 registerPotionEffectType(29, "CONDUIT_POWER", false, 1950417);1545 registerPotionEffectType(30, "DOLPHINS_GRACE", false, 8954814);1546 registerPotionEffectType(31, "BAD_OMEN", false, 745784);1547 registerPotionEffectType(32, "HERO_OF_THE_VILLAGE", false, 4521796);1548 registerPotionEffectType(33, "DARKNESS", false, 2696993);1549 PotionEffectType.stopAcceptingRegistrations();1550 }1551 private void registerPotionEffectType(int id, @NotNull String name, boolean instant, int rgb)1552 {1553 NamespacedKey key = NamespacedKey.minecraft(name.toLowerCase(Locale.ROOT));1554 PotionEffectType type = new MockPotionEffectType(key, id, name, instant, Color.fromRGB(rgb));1555 PotionEffectType.registerPotionEffectType(type);1556 }1557 @Override1558 public LootTable getLootTable(NamespacedKey key)1559 {1560 // TODO Auto-generated method stub1561 throw new UnimplementedOperationException();1562 }1563 @Override1564 public @NotNull ItemStack createExplorerMap(World world, Location location, StructureType structureType)1565 {1566 // TODO Auto-generated method stub1567 throw new UnimplementedOperationException();1568 }1569 @Override1570 public @NotNull ItemStack createExplorerMap(World world, Location location, StructureType structureType, int radius,1571 boolean findUnexplored)1572 {1573 // TODO Auto-generated method stub1574 throw new UnimplementedOperationException();1575 }1576 @Override1577 public @NotNull KeyedBossBar createBossBar(@NotNull NamespacedKey key, @NotNull String title, @NotNull BarColor color, @NotNull BarStyle style, BarFlag... flags)1578 {1579 Preconditions.checkNotNull(key, "A NamespacedKey must never be null");1580 KeyedBossBarMock bar = new KeyedBossBarMock(key, title, color, style, flags);1581 bossBars.put(key, bar);1582 return bar;1583 }1584 @Override1585 public @NotNull Iterator<KeyedBossBar> getBossBars()1586 {1587 return bossBars.values().stream().map(bossbar -> (KeyedBossBar) bossbar).iterator();1588 }1589 @Override1590 public KeyedBossBar getBossBar(NamespacedKey key)1591 {1592 Preconditions.checkNotNull(key, "A NamespacedKey must never be null");1593 return bossBars.get(key);1594 }1595 @Override1596 public boolean removeBossBar(NamespacedKey key)1597 {1598 Preconditions.checkNotNull(key, "A NamespacedKey must never be null");1599 return bossBars.remove(key, bossBars.get(key));1600 }1601 @Override1602 public @NotNull List<Entity> selectEntities(CommandSender sender, String selector)1603 {1604 // TODO Auto-generated method stub1605 throw new UnimplementedOperationException();1606 }1607 @NotNull1608 @Override1609 public StructureManager getStructureManager()1610 {1611 // TODO Auto-generated method stub1612 throw new UnimplementedOperationException();1613 }1614 @Override1615 public @Nullable <T extends Keyed> Registry<T> getRegistry(@NotNull Class<T> tClass)1616 {1617 // TODO Auto-generated method stub1618 throw new UnimplementedOperationException();1619 }1620 @Override1621 @Deprecated1622 public MapViewMock getMap(int id)1623 {1624 return mapViews.get(id);1625 }1626 @Override1627 public <T extends Keyed> @NotNull Iterable<Tag<T>> getTags(String registry, Class<T> clazz)1628 {1629 // TODO Auto-generated method stub1630 throw new UnimplementedOperationException();1631 }1632 @Override1633 @Deprecated1634 public int getTicksPerWaterSpawns()1635 {1636 // TODO Auto-generated method stub1637 throw new UnimplementedOperationException();1638 }1639 @Override1640 @Deprecated1641 public int getTicksPerAmbientSpawns()1642 {1643 // TODO Auto-generated method stub1644 throw new UnimplementedOperationException();1645 }1646 /**1647 * This returns the current time of the {@link Server} in milliseconds1648 *1649 * @return The current {@link Server} time1650 */1651 protected long getCurrentServerTime()1652 {1653 return System.currentTimeMillis();1654 }1655 @Override1656 public int getTicksPerWaterAmbientSpawns()1657 {1658 // TODO Auto-generated method stub1659 throw new UnimplementedOperationException();1660 }1661 @Override1662 @Deprecated1663 public int getTicksPerWaterUndergroundCreatureSpawns()1664 {1665 // TODO Auto-generated method stub1666 throw new UnimplementedOperationException();1667 }1668 @Override1669 @Deprecated1670 public int getWaterAmbientSpawnLimit()1671 {1672 // TODO Auto-generated method stub1673 throw new UnimplementedOperationException();1674 }1675 @Override1676 @Deprecated1677 public int getWaterUndergroundCreatureSpawnLimit()1678 {1679 // TODO Auto-generated method stub1680 throw new UnimplementedOperationException();1681 }1682 @Override1683 public int getMaxWorldSize()1684 {1685 // TODO Auto-generated method stub1686 throw new UnimplementedOperationException();1687 }1688 @Override1689 public int getSimulationDistance()1690 {1691 // TODO Auto-generated method stub1692 throw new UnimplementedOperationException();1693 }1694 @Override1695 public boolean getHideOnlinePlayers()1696 {1697 // TODO Auto-generated method stub1698 throw new UnimplementedOperationException();1699 }1700 @Override1701 public Server.@NotNull Spigot spigot()1702 {1703 return this;1704 }1705 @Override1706 public void reloadPermissions()1707 {1708 // TODO Auto-generated method stub1709 throw new UnimplementedOperationException();1710 }1711 @Override1712 public boolean reloadCommandAliases()1713 {1714 // TODO Auto-generated method stub1715 throw new UnimplementedOperationException();1716 }1717 @Override1718 public boolean suggestPlayerNamesWhenNullTabCompletions()1719 {1720 // TODO Auto-generated method stub1721 throw new UnimplementedOperationException();1722 }1723 @Override1724 public @NotNull String getPermissionMessage()1725 {1726 return unsafe.legacyComponentSerializer().serialize(NO_PERMISSION);1727 }1728 @Override1729 public @NotNull Component permissionMessage()1730 {1731 return NO_PERMISSION;1732 }1733 @Override1734 public @NotNull PlayerProfileMock createProfile(@NotNull UUID uuid)1735 {1736 return createProfile(uuid, null);1737 }1738 @Override1739 public @NotNull PlayerProfileMock createProfile(@NotNull String name)1740 {...

Full Screen

Full Screen

Source:PlayerProfileMockTest.java Github

copy

Full Screen

...135 assertEquals(0, profile.getProperties().size());136 }137 @ParameterizedTest138 @CsvSource({ "a4a7d8f6-c2df-4a0a-b12d-f0181dc85f61,Test,!?", ",Test,!?", "a4a7d8f6-c2df-4a0a-b12d-f0181dc85f61,,!?", "a4a7d8f6-c2df-4a0a-b12d-f0181dc85f61,Test," })139 void serialize(String uuid, String name, String signature)140 {141 PlayerProfileMock profile = new PlayerProfileMock(name, uuid == null ? null : UUID.fromString(uuid));142 profile.setProperty(new ProfileProperty("Key", "Value", signature));143 Map<String, Object> ser = profile.serialize();144 assertEquals(uuid, ser.get("uniqueId"));145 assertEquals(name, ser.get("name"));146 if (signature == null)147 {148 assertEquals("[{name=Key, value=Value}]", ser.get("properties").toString());149 }150 else151 {152 assertEquals("[{name=Key, value=Value, signature=" + signature + "}]", ser.get("properties").toString());153 }154 }155 @Test156 void equals()157 {...

Full Screen

Full Screen

Source:PlayerProfileMock.java Github

copy

Full Screen

...152 // TODO Auto-generated method stub153 throw new UnimplementedOperationException();154 }155 @Override156 public @NotNull Map<String, Object> serialize()157 {158 Map<String, Object> map = new LinkedHashMap<>();159 if (this.getId() != null)160 {161 map.put("uniqueId", this.getId().toString());162 }163 if (this.getName() != null)164 {165 map.put("name", getName());166 }167 if (!this.properties.isEmpty())168 {169 List<Object> propertiesData = new ArrayList<>();170 for (ProfileProperty property : this.properties)171 {172 propertiesData.add(PlayerProfileMock.serialize(property));173 }174 map.put("properties", propertiesData);175 }176 return map;177 }178 /**179 * Serializes a specific ProfileProperty.180 *181 * @param property The property to serialize.182 * @return The serialized {@link ProfileProperty}.183 */184 private static Map<String, Object> serialize(@NotNull ProfileProperty property)185 {186 Map<String, Object> map = new LinkedHashMap<>();187 map.put("name", property.getName());188 map.put("value", property.getValue());189 if (property.isSigned())190 {191 map.put("signature", property.getSignature());192 }193 return map;194 }195 @Override196 public int hashCode()197 {198 return this.properties.hashCode();...

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.entity.PlayerMock;4import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;5import org.bukkit.Bukkit;6import org.bukkit.entity.Player;7import org.junit.After;8import org.junit.Before;9import org.junit.Test;10import java.util.UUID;11public class TestClass {12 private ServerMock server;13 public void setUp() {14 server = MockBukkit.mock();15 }16 public void tearDown() {17 MockBukkit.unmock();18 }19 public void test() {20 PlayerProfileMock profile = new PlayerProfileMock(UUID.randomUUID(), "TestPlayer");21 PlayerMock player = new PlayerMock(server, profile);22 server.addPlayer(player);23 Bukkit.getOnlinePlayers().forEach(Player::getName);24 }25}26import be.seeseemelk.mockbukkit.MockBukkit;27import be.seeseemelk.mockbukkit.ServerMock;28import be.seeseemelk.mockbukkit.entity.PlayerMock;29import org.bukkit.Bukkit;30import org.bukkit.entity.Player;31import org.junit.After;32import org.junit.Before;33import org.junit.Test;34import java.util.UUID;35public class TestClass {36 private ServerMock server;37 public void setUp() {38 server = MockBukkit.mock();39 }40 public void tearDown() {41 MockBukkit.unmock();42 }43 public void test() {44 PlayerMock player = new PlayerMock(server, UUID.randomUUID());45 server.addPlayer(player);46 Bukkit.getOnlinePlayers().forEach(Player::getName);47 }48}49import be.seeseemelk.mockbukkit.MockBukkit;50import be.seeseemelk.mockbukkit.ServerMock;51import be.seeseemelk.mockbukkit.entity.PlayerMock;52import org.bukkit.Bukkit;53import org.bukkit.entity.Player;54import org.junit.After;55import org.junit.Before;56import org.junit.Test;57import java.util.UUID;58public class TestClass {

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1package be.seeseemelk.mockbukkit;2import java.lang.reflect.Field;3import java.util.UUID;4import org.bukkit.Bukkit;5import org.bukkit.OfflinePlayer;6import org.bukkit.Server;7import org.bukkit.entity.Player;8import org.bukkit.plugin.Plugin;9import org.bukkit.plugin.PluginManager;10import org.bukkit.plugin.SimplePluginManager;11import org.bukkit.plugin.java.JavaPlugin;12import org.bukkit.plugin.java.JavaPluginLoader;13import org.bukkit.scheduler.BukkitScheduler;14import org.bukkit.scheduler.BukkitTask;15import org.junit.After;16import org.junit.Before;17import org.junit.Test;18import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;19import be.seeseemelk.mockbukkit.scheduler.BukkitTaskMock;20public class PlayerProfileMockTest {21 private MockBukkit mockBukkit;22 private Server server;23 private PluginManager pluginManager;24 private BukkitScheduler scheduler;25 private PlayerProfileMock playerProfileMock;26 public void setUp() throws Exception {27 mockBukkit = MockBukkit.mock();28 server = mockBukkit.getServer();29 pluginManager = server.getPluginManager();30 scheduler = server.getScheduler();31 playerProfileMock = new PlayerProfileMock("TestPlayer", UUID.randomUUID());32 }33 public void tearDown() throws Exception {34 mockBukkit.unmock();35 }36 public void testSerialize() {37 playerProfileMock.serialize();38 }39}40package be.seeseemelk.mockbukkit;41import java.lang.reflect.Field;42import java.util.UUID;43import org.bukkit.Bukkit;44import org.bukkit.OfflinePlayer;45import org.bukkit.Server;46import org.bukkit.entity.Player;47import org.bukkit.plugin.Plugin;48import org.bukkit.plugin.PluginManager;49import org.bukkit.plugin.SimplePluginManager;50import org.bukkit.plugin.java.JavaPlugin;51import org.bukkit.plugin.java.JavaPluginLoader;52import org.bukkit.scheduler.BukkitScheduler;53import org.bukkit.scheduler.BukkitTask;54import org.junit.After;55import org.junit.Before;56import org.junit.Test;57import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;58import be.seeseemelk.mockbukkit.scheduler.BukkitTaskMock;59public class PlayerProfileMockTest {60 private MockBukkit mockBukkit;61 private Server server;62 private PluginManager pluginManager;

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1PlayerProfileMock playerProfileMock = new PlayerProfileMock();2playerProfileMock.setName("TestName");3playerProfileMock.setUniqueId(UUID.fromString("12345678-1234-1234-1234-123456789012"));4playerProfileMock.setFirstPlayed(0);5playerProfileMock.setLastPlayed(0);6playerProfileMock.setOp(false);7playerProfileMock.setWhitelisted(false);8playerProfileMock.setBanned(false);9playerProfileMock.setPlayerTime(0, false);10playerProfileMock.setPlayerWeather(WeatherType.CLEAR);11playerProfileMock.setPlayerListName("TestName");12playerProfileMock.setPlayerListHeaderFooter("TestHeader", "TestFooter");13playerProfileMock.setSleepingIgnored(false);14playerProfileMock.setPlayerTimeOffset(0);15playerProfileMock.setPlayerWeatherDuration(0);16playerProfileMock.setPlayerTimeDuration(0);17playerProfileMock.setResourcePackHash("TestHash");18playerProfileMock.setResourcePackUrl("TestUrl");19playerProfileMock.setCompassTarget(new Location(Bukkit.getWorld("world"), 0, 0, 0));20playerProfileMock.setPlayerListNameVisible(true);21playerProfileMock.setPlayerListHeaderFooterVisible(true);22playerProfileMock.setResourcePackPrompted(false);23playerProfileMock.setResourcePackAccepted(false);24playerProfileMock.setResourcePackStatus(ResourcePackStatus.SUCCESSFULLY_LOADED);25playerProfileMock.setPlayerSettings(new PlayerSettings("TestLocale", 0, 0, 0, 0, 0));26playerProfileMock.setPlayerSettingsVisible(true);27playerProfileMock.serialize();28PlayerInventoryMock playerInventoryMock = new PlayerInventoryMock();29playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_SWORD));30playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_PICKAXE));31playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_AXE));32playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_SPADE));33playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_HOE));34playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_HELMET));35playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_CHESTPLATE));36playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_LEGGINGS));37playerInventoryMock.addItem(new ItemStack(Material.DIAMOND_BOOTS));38playerInventoryMock.addItem(new ItemStack(Material.DIAMOND));

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1package be.seeseemelk.mockbukkit.profile;2import java.util.UUID;3import org.bukkit.Bukkit;4import org.bukkit.OfflinePlayer;5import org.bukkit.Server;6import org.bukkit.entity.Player;7import com.mojang.authlib.GameProfile;8import com.mojang.authlib.properties.Property;9public class PlayerProfileMock extends GameProfile {10 public PlayerProfileMock(UUID id, String name) {11 super(id, name);12 }13 public PlayerProfileMock(String name) {14 super(UUID.randomUUID(), name);15 }16 public PlayerProfileMock(UUID id) {17 super(id, null);18 }19 public PlayerProfileMock() {20 super(UUID.randomUUID(), null);21 }22 public PlayerProfileMock(GameProfile profile) {23 super(profile.getId(), profile.getName());24 for (Property property : profile.getProperties().values()) {25 this.getProperties().put(property.getName(), property);26 }27 }28 public PlayerProfileMock(OfflinePlayer player) {29 this(player.getUniqueId(), player.getName());30 }31 public PlayerProfileMock(Player player) {32 this(player.getUniqueId(), player.getName());33 }34 public GameProfile getProfile() {35 return this;36 }37 public void setProfile(GameProfile profile) {38 this.getProperties().clear();39 for (Property property : profile.getProperties().values()) {40 this.getProperties().put(property.getName(), property);41 }42 }43 public String serialize() {44 return serialize(this);45 }46 public static String serialize(GameProfile profile) {47 return profile.getId().toString() + ":" + profile.getName();48 }49 public static GameProfile deserialize(String serialized) {50 String[] parts = serialized.split(":");51 if (parts.length != 2) {52 throw new IllegalArgumentException("Invalid serialized PlayerProfileMock: " + serialized);53 }54 return new GameProfile(UUID.fromString(parts[0]), parts[1]);55 }56 public static PlayerProfileMock deserialize(String serialized, Server server) {57 String[] parts = serialized.split(":");58 if (parts.length != 2) {59 throw new IllegalArgumentException("Invalid serialized PlayerProfileMock: " + serialized);60 }61 return new PlayerProfileMock(UUID.fromString(parts[0]), parts[1]);62 }63 public boolean equals(Object obj) {64 if (obj == this) {65 return true;66 }67 if (obj == null) {68 return false;

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;2import java.io.*;3public class 2 {4 public static void main(String[] args) throws IOException, ClassNotFoundException {5 PlayerProfileMock playerProfileMock = new PlayerProfileMock("test", "test");6 playerProfileMock.setDisplayName("test");7 playerProfileMock.setPlayerUUID("test");

Full Screen

Full Screen

serialize

Using AI Code Generation

copy

Full Screen

1PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());2player.serialize(new File("test"));3PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());4player.serialize(new File("test"));5PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());6player.serialize(new File("test"));7PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());8player.serialize(new File("test"));9PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());10player.serialize(new File("test"));11PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());12player.serialize(new File("test"));13PlayerProfileMock player = new PlayerProfileMock("player", UUID.randomUUID());14player.serialize(new File("test"));

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