|
14 | 14 | import be.seeseemelk.mockbukkit.help.HelpMapMock;
|
15 | 15 | import com.mojang.brigadier.tree.CommandNode;
|
16 | 16 | import dev.jorel.commandapi.SafeVarHandle;
|
| 17 | +import dev.jorel.commandapi.test.exception.UnimplementedMethodException; |
17 | 18 | import net.minecraft.commands.Commands;
|
18 | 19 | import org.bukkit.Bukkit;
|
19 | 20 | import org.bukkit.Color;
|
@@ -273,11 +274,6 @@ public boolean isVanillaCommandWrapper(Command command) {
|
273 | 274 | return baseNMS.isVanillaCommandWrapper(command);
|
274 | 275 | }
|
275 | 276 |
|
276 |
| - @Override |
277 |
| - public Command wrapToVanillaCommandWrapper(CommandNode<CommandSourceStack> node) { |
278 |
| - return baseNMS.wrapToVanillaCommandWrapper(node); |
279 |
| - } |
280 |
| - |
281 | 277 | @Override
|
282 | 278 | public boolean isBukkitCommandWrapper(CommandNode<CommandSourceStack> node) {
|
283 | 279 | return baseNMS.isBukkitCommandWrapper(node);
|
@@ -397,152 +393,9 @@ public List<NamespacedKey> getAllRecipes() {
|
397 | 393 | return recipeManager.getRecipeIds().map(k -> new NamespacedKey(k.getNamespace(), k.getPath())).toList();
|
398 | 394 | }
|
399 | 395 |
|
400 |
| - @SuppressWarnings("unchecked") |
401 | 396 | @Override
|
402 | 397 | public <T> T getMinecraftServer() {
|
403 |
| - if (minecraftServerMock != null) { |
404 |
| - return (T) minecraftServerMock; |
405 |
| - } |
406 |
| - minecraftServerMock = Mockito.mock(MinecraftServer.class); |
407 |
| - |
408 |
| - // LootTableArgument |
409 |
| - Mockito.when(minecraftServerMock.getLootTables()).thenAnswer(invocation -> { |
410 |
| - LootTables lootTables = Mockito.mock(LootTables.class); |
411 |
| - Mockito.when(lootTables.get(any(ResourceLocation.class))).thenAnswer(i -> { |
412 |
| - if (BuiltInLootTables.all().contains(i.getArgument(0))) { |
413 |
| - return net.minecraft.world.level.storage.loot.LootTable.EMPTY; |
414 |
| - } else { |
415 |
| - return null; |
416 |
| - } |
417 |
| - }); |
418 |
| - Mockito.when(lootTables.getIds()).thenAnswer(i -> { |
419 |
| - return Streams |
420 |
| - .concat( |
421 |
| - Arrays.stream(getEntityTypes()) |
422 |
| - .filter(e -> !e.equals(EntityType.UNKNOWN)) |
423 |
| - // TODO? These entity types don't have corresponding |
424 |
| - // loot table entries! Did Spigot miss them out? |
425 |
| - .filter(e -> !e.equals(EntityType.ALLAY)) |
426 |
| - .filter(e -> !e.equals(EntityType.FROG)) |
427 |
| - .filter(e -> !e.equals(EntityType.TADPOLE)) |
428 |
| - .filter(e -> !e.equals(EntityType.WARDEN)) |
429 |
| - .filter(e -> e.isAlive()) |
430 |
| - .map(EntityType::getKey) |
431 |
| - .map(k -> new ResourceLocation("minecraft", "entities/" + k.getKey())), |
432 |
| - BuiltInLootTables.all().stream()) |
433 |
| - .collect(Collectors.toSet()); |
434 |
| - }); |
435 |
| - return lootTables; |
436 |
| - }); |
437 |
| - |
438 |
| - // AdvancementArgument |
439 |
| - Mockito.when(minecraftServerMock.getAdvancements()).thenAnswer(i -> advancementDataWorld); |
440 |
| - |
441 |
| - // TeamArgument |
442 |
| - ServerScoreboard scoreboardServerMock = Mockito.mock(ServerScoreboard.class); |
443 |
| - Mockito.when(scoreboardServerMock.getPlayerTeam(anyString())).thenAnswer(invocation -> { // Scoreboard#getPlayerTeam |
444 |
| - String teamName = invocation.getArgument(0); |
445 |
| - Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); |
446 |
| - if (team == null) { |
447 |
| - return null; |
448 |
| - } else { |
449 |
| - return new PlayerTeam(scoreboardServerMock, teamName); |
450 |
| - } |
451 |
| - }); |
452 |
| - Mockito.when(scoreboardServerMock.getObjective(anyString())).thenAnswer(invocation -> { // Scoreboard#getObjective |
453 |
| - String objectiveName = invocation.getArgument(0); |
454 |
| - org.bukkit.scoreboard.Objective bukkitObjective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); |
455 |
| - if (bukkitObjective == null) { |
456 |
| - return null; |
457 |
| - } else { |
458 |
| - return new Objective(scoreboardServerMock, objectiveName, ObjectiveCriteria.byName(bukkitObjective.getCriteria()).get(), net.minecraft.network.chat.Component.literal(bukkitObjective.getDisplayName()), switch(bukkitObjective.getRenderType()) { |
459 |
| - case HEARTS: |
460 |
| - yield RenderType.HEARTS; |
461 |
| - case INTEGER: |
462 |
| - yield RenderType.INTEGER; |
463 |
| - }); |
464 |
| - } |
465 |
| - }); |
466 |
| - Mockito.when(minecraftServerMock.getScoreboard()).thenReturn(scoreboardServerMock); // MinecraftServer#getScoreboard |
467 |
| - |
468 |
| - // WorldArgument (Dimension) |
469 |
| - Mockito.when(minecraftServerMock.getLevel(any(ResourceKey.class))).thenAnswer(invocation -> { |
470 |
| - // Get the ResourceKey<World> and extract the world name from it |
471 |
| - ResourceKey<Level> resourceKey = invocation.getArgument(0); |
472 |
| - String worldName = resourceKey.location().getPath(); |
473 |
| - |
474 |
| - // Get the world via Bukkit (returns a WorldMock) and create a |
475 |
| - // CraftWorld clone of it for WorldServer.getWorld() |
476 |
| - World world = Bukkit.getServer().getWorld(worldName); |
477 |
| - if (world == null) { |
478 |
| - return null; |
479 |
| - } else { |
480 |
| - CraftWorld craftWorldMock = Mockito.mock(CraftWorld.class); |
481 |
| - Mockito.when(craftWorldMock.getName()).thenReturn(world.getName()); |
482 |
| - Mockito.when(craftWorldMock.getUID()).thenReturn(world.getUID()); |
483 |
| - |
484 |
| - // Create our return WorldServer object |
485 |
| - ServerLevel bukkitWorldServerMock = Mockito.mock(ServerLevel.class); |
486 |
| - Mockito.when(bukkitWorldServerMock.getWorld()).thenReturn(craftWorldMock); |
487 |
| - return bukkitWorldServerMock; |
488 |
| - } |
489 |
| - }); |
490 |
| - |
491 |
| - // Player lists |
492 |
| - Mockito.when(minecraftServerMock.getPlayerList()).thenAnswer(i -> playerListMock); |
493 |
| - Mockito.when(minecraftServerMock.getPlayerList().getPlayers()).thenAnswer(i -> players); |
494 |
| - |
495 |
| - // PlayerArgument |
496 |
| - GameProfileCache userCacheMock = Mockito.mock(GameProfileCache.class); |
497 |
| - Mockito.when(userCacheMock.get(anyString())).thenAnswer(invocation -> { |
498 |
| - String playerName = invocation.getArgument(0); |
499 |
| - for (ServerPlayer onlinePlayer : players) { |
500 |
| - if (onlinePlayer.getBukkitEntity().getName().equals(playerName)) { |
501 |
| - return Optional.of(new GameProfile(onlinePlayer.getBukkitEntity().getUniqueId(), playerName)); |
502 |
| - } |
503 |
| - } |
504 |
| - return Optional.empty(); |
505 |
| - }); |
506 |
| - Mockito.when(minecraftServerMock.getProfileCache()).thenReturn(userCacheMock); |
507 |
| - |
508 |
| - // RecipeArgument |
509 |
| - Mockito.when(minecraftServerMock.getRecipeManager()).thenAnswer(i -> this.recipeManager); |
510 |
| - |
511 |
| - // FunctionArgument |
512 |
| - // We're using 2 as the function compilation level. |
513 |
| - Mockito.when(minecraftServerMock.getFunctionCompilationLevel()).thenReturn(2); |
514 |
| - Mockito.when(minecraftServerMock.getFunctions()).thenAnswer(i -> { |
515 |
| - ServerFunctionLibrary serverFunctionLibrary = Mockito.mock(ServerFunctionLibrary.class); |
516 |
| - |
517 |
| - // Functions |
518 |
| - Mockito.when(serverFunctionLibrary.getFunction(any())).thenAnswer(invocation -> Optional.ofNullable(functions.get(invocation.getArgument(0)))); |
519 |
| - Mockito.when(serverFunctionLibrary.getFunctions()).thenAnswer(invocation -> functions); |
520 |
| - |
521 |
| - // Tags |
522 |
| - Mockito.when(serverFunctionLibrary.getTag(any())).thenAnswer(invocation -> tags.getOrDefault(invocation.getArgument(0), List.of())); |
523 |
| - Mockito.when(serverFunctionLibrary.getAvailableTags()).thenAnswer(invocation -> tags.keySet()); |
524 |
| - |
525 |
| - return new ServerFunctionManager(minecraftServerMock, serverFunctionLibrary) { |
526 |
| - |
527 |
F438
| - // Make sure we don't use ServerFunctionManager#getDispatcher! |
528 |
| - // That method accesses MinecraftServer.vanillaCommandDispatcher |
529 |
| - // directly (boo) and that causes all sorts of nonsense. |
530 |
| - @Override |
531 |
| - public CommandDispatcher<CommandSourceStack> getDispatcher() { |
532 |
| - return Brigadier.getCommandDispatcher(); |
533 |
| - } |
534 |
| - }; |
535 |
| - }); |
536 |
| - |
537 |
| - Mockito.when(minecraftServerMock.getGameRules()).thenAnswer(i -> new GameRules()); |
538 |
| - Mockito.when(minecraftServerMock.getProfiler()).thenAnswer(i -> InactiveMetricsRecorder.INSTANCE.getProfiler()); |
539 |
| - |
540 |
| - // Commands object, used when creating VanillaCommandWrappers in NMS#wrapToVanillaCommandWrapper |
541 |
| - Commands commands = new Commands(); |
542 |
| - MockPlatform.setField(commands.getClass(), "g", "dispatcher", commands, getBrigadierDispatcher()); |
543 |
| - minecraftServerMock.vanillaCommandDispatcher = commands; |
544 |
| - |
545 |
| - return (T) minecraftServerMock; |
| 398 | + throw new UnimplementedMethodException("This method should not be accessed here. Please use a platform-specific version of this method."); |
546 | 399 | }
|
547 | 400 |
|
548 | 401 | @SuppressWarnings("unchecked")
|
|
0 commit comments