Exceptions { static CommandListenerWrapper from(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle().getCommandListener(); } else if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getWrapper(); } else if (sender instanceof CommandMinecart) { return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().getWrapper(); } else if (sender instanceof RemoteConsoleCommandSender) { return ((DedicatedServer) MinecraftServer.getServer()).remoteControlCommandListener.getWrapper(); } else if (sender instanceof ConsoleCommandSender) { return ((CraftServer) sender.getServer()).getServer().getServerCommandListener(); } else if (sender instanceof ProxiedCommandSender) { return ((ProxiedNativeCommandSender) sender).getHandle(); } else { throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener"); } }    }
@Test void from_exception() { CommandSender sender = mock(CommandSender.class); assertEquals( "Cannot make " + sender + " a vanilla command listener", assertThrows(IllegalArgumentException.class, () -> Exceptions.from(sender)).getMessage() ); }