Best MockBukkit code snippet using be.seeseemelk.mockbukkit.profile.PlayerProfileMock.update
Source:ServerMock.java
1package be.seeseemelk.mockbukkit;2import be.seeseemelk.mockbukkit.block.data.BlockDataMock;3import be.seeseemelk.mockbukkit.boss.BossBarMock;4import be.seeseemelk.mockbukkit.boss.KeyedBossBarMock;5import be.seeseemelk.mockbukkit.command.CommandResult;6import be.seeseemelk.mockbukkit.command.ConsoleCommandSenderMock;7import be.seeseemelk.mockbukkit.command.MessageTarget;8import be.seeseemelk.mockbukkit.command.MockCommandMap;9import be.seeseemelk.mockbukkit.enchantments.EnchantmentsMock;10import be.seeseemelk.mockbukkit.entity.EntityMock;11import be.seeseemelk.mockbukkit.entity.PlayerMock;12import be.seeseemelk.mockbukkit.entity.PlayerMockFactory;13import be.seeseemelk.mockbukkit.help.HelpMapMock;14import be.seeseemelk.mockbukkit.inventory.AnvilInventoryMock;15import be.seeseemelk.mockbukkit.inventory.BarrelInventoryMock;16import be.seeseemelk.mockbukkit.inventory.BeaconInventoryMock;17import be.seeseemelk.mockbukkit.inventory.BrewerInventoryMock;18import be.seeseemelk.mockbukkit.inventory.CartographyInventoryMock;19import be.seeseemelk.mockbukkit.inventory.ChestInventoryMock;20import be.seeseemelk.mockbukkit.inventory.DispenserInventoryMock;21import be.seeseemelk.mockbukkit.inventory.DropperInventoryMock;22import be.seeseemelk.mockbukkit.inventory.EnchantingInventoryMock;23import be.seeseemelk.mockbukkit.inventory.EnderChestInventoryMock;24import be.seeseemelk.mockbukkit.inventory.FurnaceInventoryMock;25import be.seeseemelk.mockbukkit.inventory.GrindstoneInventoryMock;26import be.seeseemelk.mockbukkit.inventory.HopperInventoryMock;27import be.seeseemelk.mockbukkit.inventory.InventoryMock;28import be.seeseemelk.mockbukkit.inventory.ItemFactoryMock;29import be.seeseemelk.mockbukkit.inventory.LecternInventoryMock;30import be.seeseemelk.mockbukkit.inventory.LoomInventoryMock;31import be.seeseemelk.mockbukkit.inventory.PlayerInventoryMock;32import be.seeseemelk.mockbukkit.inventory.ShulkerBoxInventoryMock;33import be.seeseemelk.mockbukkit.inventory.SmithingInventoryMock;34import be.seeseemelk.mockbukkit.inventory.StonecutterInventoryMock;35import be.seeseemelk.mockbukkit.inventory.WorkbenchInventoryMock;36import be.seeseemelk.mockbukkit.inventory.meta.ItemMetaMock;37import be.seeseemelk.mockbukkit.map.MapViewMock;38import be.seeseemelk.mockbukkit.plugin.PluginManagerMock;39import be.seeseemelk.mockbukkit.potion.MockPotionEffectType;40import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;41import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;42import be.seeseemelk.mockbukkit.scoreboard.ScoreboardManagerMock;43import be.seeseemelk.mockbukkit.services.ServicesManagerMock;44import be.seeseemelk.mockbukkit.tags.TagRegistry;45import be.seeseemelk.mockbukkit.tags.TagWrapperMock;46import be.seeseemelk.mockbukkit.tags.TagsMock;47import com.destroystokyo.paper.entity.ai.MobGoals;48import com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent;49import com.destroystokyo.paper.event.server.WhitelistToggleEvent;50import com.google.common.base.Preconditions;51import io.papermc.paper.datapack.DatapackManager;52import net.kyori.adventure.audience.Audience;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 {1741 return createProfile(null, name);1742 }1743 @Override1744 public @NotNull PlayerProfileMock createProfile(@Nullable UUID uuid, @Nullable String name)1745 {1746 return new PlayerProfileMock(name, uuid);1747 }1748 @Override1749 public @NotNull PlayerProfileMock createProfileExact(@Nullable UUID uuid, @Nullable String name)1750 {1751 return new PlayerProfileMock(name, uuid);1752 }1753 @Override1754 public int getCurrentTick()1755 {1756 // TODO Auto-generated method stub1757 throw new UnimplementedOperationException();1758 }1759 @Override1760 public boolean isStopping()1761 {1762 // TODO Auto-generated method stub1763 throw new UnimplementedOperationException();1764 }1765 @Override1766 public @NotNull MobGoals getMobGoals()1767 {1768 // TODO Auto-generated method stub1769 throw new UnimplementedOperationException();1770 }1771 @Override1772 public @NotNull DatapackManager getDatapackManager()1773 {1774 // TODO Auto-generated method stub1775 throw new UnimplementedOperationException();1776 }1777 @NotNull1778 @Override1779 public YamlConfiguration getConfig()1780 {1781 // TODO Auto-generated method stub1782 throw new UnimplementedOperationException();1783 }1784 @Override1785 @Deprecated1786 public void broadcast(@NotNull BaseComponent component)1787 {1788 for (Player player : getOnlinePlayers())1789 {1790 player.spigot().sendMessage(component);1791 }1792 }1793 @Override1794 @Deprecated1795 public void broadcast(@NotNull BaseComponent... components)1796 {1797 for (Player player : getOnlinePlayers())1798 {1799 player.spigot().sendMessage(components);1800 }1801 }1802 @Override1803 public void restart()1804 {1805 throw new UnsupportedOperationException("Not supported.");1806 }1807 @Override1808 public int getTicksPerSpawns(@NotNull SpawnCategory spawnCategory)1809 {1810 // TODO Auto-generated method stub1811 throw new UnimplementedOperationException();1812 }1813 @Override1814 @Deprecated1815 public @NotNull PlayerProfileMock createPlayerProfile(@Nullable UUID uniqueId, @Nullable String name)1816 {1817 return new PlayerProfileMock(name, uniqueId);1818 }1819 @Override1820 @Deprecated1821 public @NotNull PlayerProfileMock createPlayerProfile(@NotNull UUID uniqueId)1822 {1823 return createPlayerProfile(uniqueId, null);1824 }1825 @Override1826 @Deprecated1827 public @NotNull PlayerProfileMock createPlayerProfile(@NotNull String name)1828 {1829 return createPlayerProfile(null, name);1830 }1831 @Override1832 public int getSpawnLimit(@NotNull SpawnCategory spawnCategory)1833 {1834 // TODO Auto-generated method stub1835 throw new UnimplementedOperationException();1836 }1837 @Override1838 public @NotNull PotionBrewer getPotionBrewer()1839 {1840 // TODO Auto-generated method stub1841 throw new UnimplementedOperationException();1842 }1843 @Override1844 public @NotNull File getPluginsFolder()1845 {1846 try1847 {1848 return getPluginManager().getParentTemporaryDirectory();1849 }1850 catch (IOException e)1851 {1852 throw new RuntimeException(e);1853 }1854 }1855 @Override1856 public @NotNull Iterable<? extends Audience> audiences()1857 {1858 // TODO Auto-generated method stub1859 throw new UnimplementedOperationException();1860 }1861}...
Source:PlayerProfileMock.java
...116 // TODO Auto-generated method stub117 throw new UnimplementedOperationException();118 }119 @Override120 public @NotNull CompletableFuture<PlayerProfile> update()121 {122 // TODO Auto-generated method stub123 throw new UnimplementedOperationException();124 }125 @Override126 public boolean completeFromCache()127 {128 // TODO Auto-generated method stub129 throw new UnimplementedOperationException();130 }131 @Override132 public boolean completeFromCache(boolean onlineMode)133 {134 // TODO Auto-generated method stub...
update
Using AI Code Generation
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.entity.Player;6import org.junit.After;7import org.junit.Before;8import org.junit.Test;9import java.util.UUID;10public class Test2 {11 private ServerMock server;12 private PlayerMock player;13 private PlayerProfileMock profile;14 public void setUp() {15 server = MockBukkit.mock();16 player = server.addPlayer();17 profile = player.getProfile();18 }19 public void tearDown() {20 MockBukkit.unmock();21 }22 public void test1() {23 profile.update();24 }25 public void test2() {26 profile.update();27 }28}29import be.seeseemelk.mockbukkit.MockBukkit;30import be.seeseemelk.mockbukkit.ServerMock;31import be.seeseemelk.mockbukkit.entity.PlayerMock;32import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;33import org.bukkit.entity.Player;34import org.junit.After;35import org.junit.Before;36import org.junit.Test;37import java.util.UUID;38public class Test3 {39 private ServerMock server;40 private PlayerMock player;41 private PlayerProfileMock profile;42 public void setUp() {43 server = MockBukkit.mock();44 player = server.addPlayer();45 profile = player.getProfile();46 }47 public void tearDown() {48 MockBukkit.unmock();49 }50 public void test1() {51 profile.update();52 }53 public void test2() {54 profile.update();55 }56}57import be.seeseemelk.mockbukkit.MockBukkit;58import be.seeseemelk.mockbukkit.ServerMock;59import be.seeseemelk.mockbukkit.entity.PlayerMock;60import be.seeseemelk.mockbukkit.profile
update
Using AI Code Generation
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.junit.jupiter.api.AfterEach;7import org.junit.jupiter.api.BeforeEach;8import org.junit.jupiter.api.Test;9public class TestPlayerProfileMock {10 private ServerMock server;11 private PlayerMock player;12 private PlayerProfileMock profile;13 public void setUp()14 {15 server = MockBukkit.mock();16 player = server.addPlayer();17 profile = player.getProfile();18 }19 public void tearDown()20 {21 MockBukkit.unmock();22 }23 public void testUpdate()24 {25 profile.update();26 }27}28import be.seeseemelk.mockbukkit.MockBukkit;29import be.seeseemelk.mockbukkit.ServerMock;30import be.seeseemelk.mockbukkit.entity.PlayerMock;31import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;32import org.bukkit.Bukkit;33import org.junit.jupiter.api.AfterEach;34import org.junit.jupiter.api.BeforeEach;35import org.junit.jupiter.api.Test;36public class TestPlayerProfileMock {37 private ServerMock server;38 private PlayerMock player;39 private PlayerProfileMock profile;40 public void setUp()41 {42 server = MockBukkit.mock();43 player = server.addPlayer();44 profile = player.getProfile();45 }46 public void tearDown()47 {48 MockBukkit.unmock();49 }50 public void testUpdate()51 {52 profile.update();53 }54}55import be.seeseemelk.mockbukkit.MockBukkit;56import be.seeseemelk.mockbukkit.ServerMock;57import be.seeseemelk.mockbukkit.entity.PlayerMock;58import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;59import org.bukkit.Bukkit;60import org.junit.jupiter.api.After
update
Using AI Code Generation
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.entity.Player;6import org.junit.jupiter.api.AfterAll;7import org.junit.jupiter.api.BeforeAll;8import org.junit.jupiter.api.Test;9import static org.junit.jupiter.api.Assertions.*;10public class PlayerProfileMockTest {11 private static ServerMock server;12 private static PlayerMock player;13 public static void setUp() {14 server = MockBukkit.mock();15 player = server.addPlayer();16 }17 public static void tearDown() {18 MockBukkit.unmock();19 }20 public void testUpdate() {21 PlayerProfileMock profile = player.getPlayerProfile();22 profile.update();23 assertEquals(profile, player.getPlayerProfile());24 }25}26import be.seeseemelk.mockbukkit.MockBukkit;27import be.seeseemelk.mockbukkit.ServerMock;28import be.seeseemelk.mockbukkit.entity.PlayerMock;29import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;30import org.bukkit.entity.Player;31import org.junit.jupiter.api.AfterAll;32import org.junit.jupiter.api.BeforeAll;33import org.junit.jupiter.api.Test;34import static org.junit.jupiter.api.Assertions.*;35public class PlayerProfileMockTest {36 private static ServerMock server;37 private static PlayerMock player;38 public static void setUp() {39 server = MockBukkit.mock();40 player = server.addPlayer();41 }42 public static void tearDown() {43 MockBukkit.unmock();44 }45 public void testUpdate() {46 PlayerProfileMock profile = player.getPlayerProfile();47 profile.update();48 assertEquals(profile, player.getPlayerProfile());49 }50}51import be.seeseemelk.mockbukkit.MockBukkit;52import be.seeseemelk.mockbukkit.ServerMock;53import be.seeseemelk.mockbukkit.entity.PlayerMock
update
Using AI Code Generation
1import static org.junit.Assert.assertEquals;2import org.bukkit.Bukkit;3import org.bukkit.entity.Player;4import org.junit.After;5import org.junit.Before;6import org.junit.Test;7import be.seeseemelk.mockbukkit.MockBukkit;8import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;9public class Test2 {10 public void setUp() throws Exception {11 MockBukkit.mock();12 }13 public void tearDown() {14 MockBukkit.unmock();15 }16 public void test() {17 PlayerProfileMock profile = new PlayerProfileMock("test", "test");18 Player player = Bukkit.getServer().loadPlayer(profile);19 assertEquals("test", player.getName());20 profile.update("test2", "test2");21 assertEquals("test2", player.getName());22 }23}24import static org.junit.Assert.assertEquals;25import org.bukkit.Bukkit;26import org.bukkit.entity.Player;27import org.junit.After;28import org.junit.Before;29import org.junit.Test;30import be.seeseemelk.mockbukkit.MockBukkit;31import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;32public class Test3 {33 public void setUp() throws Exception {34 MockBukkit.mock();35 }36 public void tearDown() {37 MockBukkit.unmock();38 }39 public void test() {40 PlayerProfileMock profile = new PlayerProfileMock("test", "test");41 Player player = Bukkit.getServer().loadPlayer(profile);42 assertEquals("test", player.getName());43 profile.setPlayerName("test2");44 assertEquals("test2", player.getName());45 }46}47import static org.junit.Assert.assertEquals;48import org.bukkit.Bukkit;49import org.bukkit.entity.Player;50import org.junit.After;51import org.junit.Before;52import org.junit.Test;53import be.seeseemelk.mockbukkit.MockBukkit;54import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;55public class Test1 {56 public void setUp() throws Exception {57 MockBukkit.mock();58 }
update
Using AI Code Generation
1import java.util.UUID;2import org.bukkit.Bukkit;3import org.bukkit.Material;4import org.bukkit.OfflinePlayer;5import org.bukkit.entity.Player;6import be.seeseemelk.mockbukkit.MockBukkit;7import be.seeseemelk.mockbukkit.ServerMock;8import be.seeseemelk.mockbukkit.entity.PlayerMock;9import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;10import be.seeseemelk.mockbukkit.profile.PlayerProfileRepositoryMock;11public class MockBukkitTest {12 public static void main(String[] args) {13 ServerMock server = MockBukkit.mock();14 PlayerProfileRepositoryMock profileRepository = server.getPlayerProfileRepository();
update
Using AI Code Generation
1import org.junit.jupiter.api.Test;2import org.junit.jupiter.api.extension.ExtendWith;3import org.mockito.junit.jupiter.MockitoExtension;4import org.bukkit.Bukkit;5import org.bukkit.OfflinePlayer;6import org.bukkit.entity.Player;7import org.bukkit.plugin.Plugin;8import org.bukkit.plugin.PluginManager;9import org.bukkit.plugin.java.JavaPlugin;10import org.bukkit.plugin.java.JavaPluginLoader;11import be.seeseemelk.mockbukkit.MockBukkit;12import be.seeseemelk.mockbukkit.ServerMock;13import be.seeseemelk.mockbukkit.entity.PlayerMock;14import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;15@ExtendWith(MockitoExtension.class)16{17 private ServerMock server;18 private PluginManager pluginManager;19 private Plugin plugin;20 public void test()21 {22 server = MockBukkit.mock();23 pluginManager = server.getPluginManager();24 plugin = new JavaPlugin()25 {26 public void onLoad()27 {28 pluginManager.registerInterface(JavaPluginLoader.class);29 }30 };31 plugin.onLoad();32 PlayerMock player = server.addPlayer();33 player.setDisplayName("test");34 player.setPlayerListName("test");35 player.setPlayerListHeader("test");36 player.setPlayerListFooter("test");37 player.setPlayerListHeaderFooter("test", "test");38 player.setPlayerTime(0, false);39 player.setCompassTarget(new Location(player.getWorld(), 0, 0, 0));40 PlayerProfileMock profile = player.getPlayerProfile();41 profile.update(player);42 OfflinePlayer offlinePlayer = server.getOfflinePlayer(player.getUniqueId());43 profile.update(offlinePlayer);44 }45}46import org.junit.jupiter.api.Test;47import org.junit.jupiter.api.extension.ExtendWith;48import org.mockito.junit.jupiter.MockitoExtension;49import org.bukkit.Bukkit;50import org.bukkit.OfflinePlayer;51import org.bukkit.entity.Player;52import org.bukkit.plugin.Plugin;53import org.bukkit.plugin.PluginManager;54import org.bukkit.plugin.java.JavaPlugin;55import org.bukkit.plugin.java.JavaPluginLoader;56import be.seeseemelk.mockbukkit.MockBukkit;57import be.seeseemelk.mockbukkit.ServerMock;58import be.seeseemelk.mockbukkit.entity
update
Using AI Code Generation
1package com.example.demo;2import org.bukkit.entity.Player;3import org.junit.jupiter.api.Test;4import be.seeseemelk.mockbukkit.MockBukkit;5import be.seeseemelk.mockbukkit.ServerMock;6import be.seeseemelk.mockbukkit.entity.PlayerMock;7import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;8public class DemoTest {9 public void setPlayerSkin() {10 ServerMock server = MockBukkit.mock();11 PlayerMock playerMock = server.addPlayer();12 Player player = playerMock.getPlayer();
update
Using AI Code Generation
1public class 2 extends JavaPlugin implements Listener {2 public void onEnable() {3 getServer().getPluginManager().registerEvents(this, this);4 }5 public void onCommand(PlayerCommandPreprocessEvent event) {6 if (event.getMessage().startsWith("/name")) {7 String[] args = event.getMessage().split(" ");8 if (args.length == 2) {9 Player player = event.getPlayer();10 PlayerProfileMock profile = new PlayerProfileMock(player.getUniqueId(), player.getName());11 profile.update(args[1]);12 player.setPlayerProfile(profile);13 }14 }15 }16}17public class 3 extends JavaPlugin implements Listener {18 public void onEnable() {19 getServer().getPluginManager().registerEvents(this, this);20 }21 public void onCommand(PlayerCommandPreprocessEvent event) {22 if (event.getMessage().startsWith("/name")) {23 String[] args = event.getMessage().split(" ");24 if (args.length == 2) {25 Player player = event.getPlayer();26 PlayerProfileMock profile = new PlayerProfileMock(player.getUniqueId(), player.getName());27 profile.update(args[1]);28 player.setPlayerProfile(profile);29 }30 }31 }32}33public class 4 extends JavaPlugin implements Listener {34 public void onEnable() {35 getServer().getPluginManager().registerEvents(this, this);36 }37 public void onCommand(PlayerCommandPreprocessEvent event) {38 if (event.getMessage().startsWith("/name")) {39 String[] args = event.getMessage().split(" ");40 if (args.length == 2) {41 Player player = event.getPlayer();42 PlayerProfileMock profile = new PlayerProfileMock(player.getUniqueId(), player.getName());43 profile.update(args[1]);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!